Skip to content

Commit

Permalink
GUIEditBox: Use primary selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Desour committed Apr 27, 2023
1 parent d197ff0 commit 062b4d0
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/gui/guiEditBox.cpp
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -774,6 +786,34 @@ bool GUIEditBox::processMouse(const SEvent &event)
return true;
}
break;
case EMIE_MMOUSE_PRESSED_DOWN: {
if (!AbsoluteClippingRect.isPointInside(core::position2d<s32>(
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;
}
Expand Down

0 comments on commit 062b4d0

Please sign in to comment.