From 6d0406edd93a211e4e95265de3699f83e22361bf Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sat, 14 Nov 2020 11:07:57 +0200 Subject: Fixed copying the URL input field contents --- src/ui/inputwidget.c | 30 ++++++++++++++++++++---------- src/ui/window.c | 2 +- 2 files changed, 21 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index 537afb00..fbcbd4c2 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c @@ -479,6 +479,21 @@ static size_t coordIndex_InputWidget_(const iInputWidget *d, iInt2 coord) { return index; } +static iBool copy_InputWidget_(iInputWidget *d, iBool doCut) { + if (!isEmpty_Range(&d->mark)) { + const iRanges m = mark_InputWidget_(d); + SDL_SetClipboardText(cstrCollect_String( + newUnicodeN_String(constAt_Array(&d->text, m.start), size_Range(&m)))); + if (doCut) { + pushUndo_InputWidget_(d); + deleteMarked_InputWidget_(d); + contentsWereChanged_InputWidget_(d); + } + return iTrue; + } + return iFalse; +} + static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { iWidget *w = as_Widget(d); if (isCommand_Widget(w, ev, "focus.gained")) { @@ -495,6 +510,10 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { } return iFalse; } + else if (isFocused_Widget(d) && isCommand_UserEvent(ev, "copy")) { + copy_InputWidget_(d, iFalse); + return iTrue; + } switch (processEvent_Click(&d->click, ev)) { case none_ClickResult: break; @@ -531,16 +550,7 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { switch (key) { case 'c': case 'x': - if (!isEmpty_Range(&d->mark)) { - const iRanges m = mark_InputWidget_(d); - SDL_SetClipboardText(cstrCollect_String( - newUnicodeN_String(constAt_Array(&d->text, m.start), size_Range(&m)))); - if (key == 'x') { - pushUndo_InputWidget_(d); - deleteMarked_InputWidget_(d); - contentsWereChanged_InputWidget_(d); - } - } + copy_InputWidget_(d, key == 'x'); return iTrue; case 'v': if (SDL_HasClipboardText()) { diff --git a/src/ui/window.c b/src/ui/window.c index 2b2dae46..115dd04b 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -125,7 +125,7 @@ static const iMenuItem fileMenuItems[] = { }; static const iMenuItem editMenuItems[] = { - { "Copy Source Text", SDLK_c, KMOD_PRIMARY, "copy" }, + { "Copy", SDLK_c, KMOD_PRIMARY, "copy" }, { "Copy Link to Page", SDLK_c, KMOD_PRIMARY | KMOD_SHIFT, "document.copylink" }, { "---", 0, 0, NULL }, { "Find", SDLK_f, KMOD_PRIMARY, "focus.set id:find.input" }, -- cgit v1.2.3