diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-11-14 11:07:57 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-11-14 11:07:57 +0200 |
commit | 6d0406edd93a211e4e95265de3699f83e22361bf (patch) | |
tree | dcf4ee90b9f40c57e55e553e895e3f250b4d0823 /src/ui/inputwidget.c | |
parent | 70b1483eb567dd44b603d0f4f5338b7df0e99959 (diff) |
Fixed copying the URL input field contents
Diffstat (limited to 'src/ui/inputwidget.c')
-rw-r--r-- | src/ui/inputwidget.c | 30 |
1 files changed, 20 insertions, 10 deletions
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) { | |||
479 | return index; | 479 | return index; |
480 | } | 480 | } |
481 | 481 | ||
482 | static iBool copy_InputWidget_(iInputWidget *d, iBool doCut) { | ||
483 | if (!isEmpty_Range(&d->mark)) { | ||
484 | const iRanges m = mark_InputWidget_(d); | ||
485 | SDL_SetClipboardText(cstrCollect_String( | ||
486 | newUnicodeN_String(constAt_Array(&d->text, m.start), size_Range(&m)))); | ||
487 | if (doCut) { | ||
488 | pushUndo_InputWidget_(d); | ||
489 | deleteMarked_InputWidget_(d); | ||
490 | contentsWereChanged_InputWidget_(d); | ||
491 | } | ||
492 | return iTrue; | ||
493 | } | ||
494 | return iFalse; | ||
495 | } | ||
496 | |||
482 | static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { | 497 | static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { |
483 | iWidget *w = as_Widget(d); | 498 | iWidget *w = as_Widget(d); |
484 | if (isCommand_Widget(w, ev, "focus.gained")) { | 499 | if (isCommand_Widget(w, ev, "focus.gained")) { |
@@ -495,6 +510,10 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { | |||
495 | } | 510 | } |
496 | return iFalse; | 511 | return iFalse; |
497 | } | 512 | } |
513 | else if (isFocused_Widget(d) && isCommand_UserEvent(ev, "copy")) { | ||
514 | copy_InputWidget_(d, iFalse); | ||
515 | return iTrue; | ||
516 | } | ||
498 | switch (processEvent_Click(&d->click, ev)) { | 517 | switch (processEvent_Click(&d->click, ev)) { |
499 | case none_ClickResult: | 518 | case none_ClickResult: |
500 | break; | 519 | break; |
@@ -531,16 +550,7 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { | |||
531 | switch (key) { | 550 | switch (key) { |
532 | case 'c': | 551 | case 'c': |
533 | case 'x': | 552 | case 'x': |
534 | if (!isEmpty_Range(&d->mark)) { | 553 | copy_InputWidget_(d, key == 'x'); |
535 | const iRanges m = mark_InputWidget_(d); | ||
536 | SDL_SetClipboardText(cstrCollect_String( | ||
537 | newUnicodeN_String(constAt_Array(&d->text, m.start), size_Range(&m)))); | ||
538 | if (key == 'x') { | ||
539 | pushUndo_InputWidget_(d); | ||
540 | deleteMarked_InputWidget_(d); | ||
541 | contentsWereChanged_InputWidget_(d); | ||
542 | } | ||
543 | } | ||
544 | return iTrue; | 554 | return iTrue; |
545 | case 'v': | 555 | case 'v': |
546 | if (SDL_HasClipboardText()) { | 556 | if (SDL_HasClipboardText()) { |