From d86abb40c1276ec74c72caef664d8efe3915c190 Mon Sep 17 00:00:00 2001 From: Desour Date: Tue, 23 Aug 2022 18:55:08 +0200 Subject: [PATCH] CGUIEditBox: Use primary selection This is essentially the same as the commit in the minetest repo for GUIEditBox. --- source/Irrlicht/CGUIEditBox.cpp | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/source/Irrlicht/CGUIEditBox.cpp b/source/Irrlicht/CGUIEditBox.cpp index cf4b64e..24b8099 100644 --- a/source/Irrlicht/CGUIEditBox.cpp +++ b/source/Irrlicht/CGUIEditBox.cpp @@ -1135,6 +1135,34 @@ bool CGUIEditBox::processMouse(const SEvent& event) return true; } } + case EMIE_MMOUSE_PRESSED_DOWN: { + if (!AbsoluteClippingRect.isPointInside(core::position2d( + event.MouseInput.X, event.MouseInput.Y))) + return false; + + if (!Environment->hasFocus(this)) { + BlinkStartTime = os::Timer::getTime(); + } + + // move cursor and disable marking + CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y); + MouseMarking = false; + setTextMarkers(CursorPos, CursorPos); + + // paste from the primary selection + inputString([&] { + irr::core::stringw inserted_text; + if (!Operator) + return inserted_text; + const c8 *inserted_text_utf8 = Operator->getTextFromPrimarySelection(); + if (!inserted_text_utf8) + return inserted_text; + core::multibyteToWString(inserted_text, inserted_text_utf8); + return inserted_text; + }()); + + return true; + } default: break; } @@ -1624,6 +1652,17 @@ void CGUIEditBox::setTextMarkers(s32 begin, s32 end) { MarkBegin = begin; MarkEnd = end; + + if (!PasswordBox && Operator && MarkBegin != MarkEnd) { + // copy to primary selection + const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; + const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; + + core::stringc s; + wStringToMultibyte(s, Text.subString(realmbgn, realmend - realmbgn)); + Operator->copyToPrimarySelection(s.c_str()); + } + sendGuiEvent(EGET_EDITBOX_MARKING_CHANGED); } }