From ac987ccb8d177764308f09e9cf7068a7df8f0890 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Thu, 22 Jul 2021 21:57:20 +0300 Subject: InputWidget: Fixed multiline deletion; arrow key events --- src/ui/inputwidget.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index 2c1c3165..b695b5c9 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c @@ -1225,30 +1225,25 @@ static void contentsWereChanged_InputWidget_(iInputWidget *d) { static void deleteIndexRange_InputWidget_(iInputWidget *d, iRanges deleted) { size_t firstModified = iInvalidPos; - for (size_t i = 0; i < size_Array(&d->lines); i++) { + for (int i = size_Array(&d->lines) - 1; i >= 0; i--) { iInputLine *line = at_Array(&d->lines, i); - if (line->range.end < deleted.start) { - continue; - } - if (line->range.start >= deleted.end) { + if (line->range.end <= deleted.start) { break; } - if (firstModified == iInvalidPos) { - firstModified = i; + if (line->range.start >= deleted.end) { + continue; } + firstModified = i; if (line->range.start >= deleted.start && line->range.end <= deleted.end) { - /* Delete the entire line. */ - deinit_InputLine(line); - remove_Array(&d->lines, i--); - continue; + clear_String(&line->text); } else if (deleted.start > line->range.start && deleted.end >= line->range.end) { truncate_Block(&line->text.chars, deleted.start - line->range.start); } - else if (deleted.start <= line->range.start && deleted.end < line->range.end) { + else if (deleted.start <= line->range.start && deleted.end <= line->range.end) { remove_Block(&line->text.chars, 0, deleted.end - line->range.start); } - else if (deleted.start > line->range.start && deleted.end < line->range.end) { + else if (deleted.start > line->range.start && deleted.end <= line->range.end) { remove_Block(&line->text.chars, deleted.start - line->range.start, size_Range(&deleted)); } else { @@ -1497,6 +1492,10 @@ static void lineTextWasChanged_InputWidget_(iInputWidget *d, iInputLine *line) { textOfLinesWasChanged_InputWidget_(d, (iRangei){ y, y + 1 }); } +static iBool isArrowUpDownConsumed_InputWidget_(const iInputWidget *d) { + return d->maxWrapLines > 1; +} + static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { iWidget *w = as_Widget(d); if (isCommand_Widget(w, ev, "focus.gained")) { @@ -1854,6 +1853,9 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { refresh_Widget(d); return iTrue; } + if (isArrowUpDownConsumed_InputWidget_(d)) { + return iTrue; + } /* For moving to lookup from url entry. */ return processEvent_Widget(as_Widget(d), ev); case SDLK_PAGEUP: -- cgit v1.2.3