Skip to content

Commit dad87a3

Browse files
authoredAug 23, 2021
Use utf-8 for the Irrlicht clipboard (#11538)
1 parent fad835c commit dad87a3

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed
 

Diff for: ‎src/gui/guiChatConsole.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ void GUIChatConsole::drawText()
338338
false,
339339
false,
340340
&AbsoluteClippingRect);
341-
} else
341+
} else
342342
#endif
343343
{
344344
// Otherwise use standard text
@@ -580,8 +580,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
580580
const c8 *text = os_operator->getTextFromClipboard();
581581
if (!text)
582582
return true;
583-
std::basic_string<unsigned char> str((const unsigned char*)text);
584-
prompt.input(std::wstring(str.begin(), str.end()));
583+
prompt.input(utf8_to_wide(text));
585584
return true;
586585
}
587586
else if(event.KeyInput.Key == KEY_KEY_X && event.KeyInput.Control)

Diff for: ‎src/gui/guiEditBox.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2525
#include "IGUIFont.h"
2626

2727
#include "porting.h"
28+
#include "util/string.h"
2829

2930
GUIEditBox::~GUIEditBox()
3031
{
@@ -517,8 +518,7 @@ void GUIEditBox::onKeyControlC(const SEvent &event)
517518
const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end;
518519
const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin;
519520

520-
core::stringc s;
521-
s = Text.subString(realmbgn, realmend - realmbgn).c_str();
521+
std::string s = stringw_to_utf8(Text.subString(realmbgn, realmend - realmbgn));
522522
m_operator->copyToClipboard(s.c_str());
523523
}
524524

@@ -567,29 +567,28 @@ bool GUIEditBox::onKeyControlV(const SEvent &event, s32 &mark_begin, s32 &mark_e
567567

568568
// add new character
569569
if (const c8 *p = m_operator->getTextFromClipboard()) {
570+
core::stringw inserted_text = utf8_to_stringw(p);
570571
if (m_mark_begin == m_mark_end) {
571572
// insert text
572573
core::stringw s = Text.subString(0, m_cursor_pos);
573-
s.append(p);
574+
s.append(inserted_text);
574575
s.append(Text.subString(
575576
m_cursor_pos, Text.size() - m_cursor_pos));
576577

577578
if (!m_max || s.size() <= m_max) {
578579
Text = s;
579-
s = p;
580-
m_cursor_pos += s.size();
580+
m_cursor_pos += inserted_text.size();
581581
}
582582
} else {
583583
// replace text
584584

585585
core::stringw s = Text.subString(0, realmbgn);
586-
s.append(p);
586+
s.append(inserted_text);
587587
s.append(Text.subString(realmend, Text.size() - realmend));
588588

589589
if (!m_max || s.size() <= m_max) {
590590
Text = s;
591-
s = p;
592-
m_cursor_pos = realmbgn + s.size();
591+
m_cursor_pos = realmbgn + inserted_text.size();
593592
}
594593
}
595594
}

0 commit comments

Comments
 (0)
Please sign in to comment.