From 062b4d036a38d21539f56d7ef8000dae094c46cf Mon Sep 17 00:00:00 2001 From: Desour Date: Tue, 23 Aug 2022 18:46:10 +0200 Subject: [PATCH] GUIEditBox: Use primary selection --- src/gui/guiEditBox.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/gui/guiEditBox.cpp b/src/gui/guiEditBox.cpp index b6ee71ce9ed5..be6731653b3a 100644 --- a/src/gui/guiEditBox.cpp +++ b/src/gui/guiEditBox.cpp @@ -177,6 +177,18 @@ void GUIEditBox::setTextMarkers(s32 begin, s32 end) if (begin != m_mark_begin || end != m_mark_end) { m_mark_begin = begin; m_mark_end = end; + +#if IRRLICHT_VERSION_MT_REVISION >= 11 + if (!m_passwordbox && m_operator && m_mark_begin != m_mark_end) { + // copy to primary selection + 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; + + std::string s = stringw_to_utf8(Text.subString(realmbgn, realmend - realmbgn)); + m_operator->copyToPrimarySelection(s.c_str()); + } +#endif + sendGuiEvent(EGET_EDITBOX_MARKING_CHANGED); } } @@ -774,6 +786,34 @@ bool GUIEditBox::processMouse(const SEvent &event) return true; } break; + case EMIE_MMOUSE_PRESSED_DOWN: { + if (!AbsoluteClippingRect.isPointInside(core::position2d( + event.MouseInput.X, event.MouseInput.Y))) + return false; + + if (!Environment->hasFocus(this)) { + m_blink_start_time = porting::getTimeMs(); + } + + // move cursor and disable marking + m_cursor_pos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); + m_mouse_marking = false; + setTextMarkers(m_cursor_pos, m_cursor_pos); + +#if IRRLICHT_VERSION_MT_REVISION >= 11 + // paste from the primary selection + inputString([&] { + if (!m_operator) + return core::stringw(); + const c8 *inserted_text_utf8 = m_operator->getTextFromPrimarySelection(); + if (!inserted_text_utf8) + return core::stringw(); + return utf8_to_stringw(inserted_text_utf8); + }()); +#endif + + return true; + } default: break; }