diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-09-19 20:56:13 +0200 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-09-19 20:56:13 +0200 |
commit | c8900e169a1ddceec07a449f1ae7c4322ff02036 (patch) | |
tree | 5156605fb473d25786426eb6876ba2e7d3b7507b /src/gui/guiEditBox.cpp | |
parent | 950d2c9b3e10cbace9236e820c8119d1abb9e01f (diff) | |
parent | e0529da5c84f224c380e6d5e063392cb01f85683 (diff) | |
download | dragonfireclient-c8900e169a1ddceec07a449f1ae7c4322ff02036.tar.xz |
Merge branch 'master' of https://github.com/minetest/minetest
Diffstat (limited to 'src/gui/guiEditBox.cpp')
-rw-r--r-- | src/gui/guiEditBox.cpp | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/gui/guiEditBox.cpp b/src/gui/guiEditBox.cpp index ba548aa2d..8459107cd 100644 --- a/src/gui/guiEditBox.cpp +++ b/src/gui/guiEditBox.cpp @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "IGUIFont.h" #include "porting.h" +#include "util/string.h" GUIEditBox::~GUIEditBox() { @@ -232,10 +233,6 @@ bool GUIEditBox::OnEvent(const SEvent &event) bool GUIEditBox::processKey(const SEvent &event) { - if (!m_writable) { - return false; - } - if (!event.KeyInput.PressedDown) return false; @@ -521,8 +518,7 @@ void GUIEditBox::onKeyControlC(const SEvent &event) const s32 realmbgn = m_mark_begin < m_mark_end ? m_mark_begin : m_mark_end; const s32 realmend = m_mark_begin < m_mark_end ? m_mark_end : m_mark_begin; - core::stringc s; - s = Text.subString(realmbgn, realmend - realmbgn).c_str(); + std::string s = stringw_to_utf8(Text.subString(realmbgn, realmend - realmbgn)); m_operator->copyToClipboard(s.c_str()); } @@ -531,6 +527,9 @@ bool GUIEditBox::onKeyControlX(const SEvent &event, s32 &mark_begin, s32 &mark_e // First copy to clipboard onKeyControlC(event); + if (!m_writable) + return false; + if (m_passwordbox || !m_operator || m_mark_begin == m_mark_end) return false; @@ -556,7 +555,7 @@ bool GUIEditBox::onKeyControlX(const SEvent &event, s32 &mark_begin, s32 &mark_e bool GUIEditBox::onKeyControlV(const SEvent &event, s32 &mark_begin, s32 &mark_end) { - if (!isEnabled()) + if (!isEnabled() || !m_writable) return false; // paste from the clipboard @@ -568,29 +567,28 @@ bool GUIEditBox::onKeyControlV(const SEvent &event, s32 &mark_begin, s32 &mark_e // add new character if (const c8 *p = m_operator->getTextFromClipboard()) { + core::stringw inserted_text = utf8_to_stringw(p); if (m_mark_begin == m_mark_end) { // insert text core::stringw s = Text.subString(0, m_cursor_pos); - s.append(p); + s.append(inserted_text); s.append(Text.subString( m_cursor_pos, Text.size() - m_cursor_pos)); if (!m_max || s.size() <= m_max) { Text = s; - s = p; - m_cursor_pos += s.size(); + m_cursor_pos += inserted_text.size(); } } else { // replace text core::stringw s = Text.subString(0, realmbgn); - s.append(p); + s.append(inserted_text); s.append(Text.subString(realmend, Text.size() - realmend)); if (!m_max || s.size() <= m_max) { Text = s; - s = p; - m_cursor_pos = realmbgn + s.size(); + m_cursor_pos = realmbgn + inserted_text.size(); } } } @@ -602,7 +600,7 @@ bool GUIEditBox::onKeyControlV(const SEvent &event, s32 &mark_begin, s32 &mark_e bool GUIEditBox::onKeyBack(const SEvent &event, s32 &mark_begin, s32 &mark_end) { - if (!isEnabled() || Text.empty()) + if (!isEnabled() || Text.empty() || !m_writable) return false; core::stringw s; @@ -640,7 +638,7 @@ bool GUIEditBox::onKeyBack(const SEvent &event, s32 &mark_begin, s32 &mark_end) bool GUIEditBox::onKeyDelete(const SEvent &event, s32 &mark_begin, s32 &mark_end) { - if (!isEnabled() || Text.empty()) + if (!isEnabled() || Text.empty() || !m_writable) return false; core::stringw s; |