From c8fcbe53279d9537895e17e15047b0142d24e4a1 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Wed, 15 Dec 2021 13:40:48 +0200 Subject: InputWidget: Initial scroll position out of bounds --- src/ui/inputwidget.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index 8d58eac9..49cc0a1e 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c @@ -558,6 +558,9 @@ static iInt2 relativeCursorCoord_InputWidget_(const iInputWidget *d) { } static void updateVisible_InputWidget_(iInputWidget *d) { + if (width_Widget(d) == 0) { + return; /* Nothing to do yet. */ + } const int totalWraps = numWrapLines_InputWidget_(d); const int visWraps = iClamp(totalWraps, d->minWrapLines, d->maxWrapLines); /* Resize the height of the editor. */ @@ -575,6 +578,14 @@ static void updateVisible_InputWidget_(iInputWidget *d) { else if (cursorY < d->visWrapLines.start) { delta = cursorY - d->visWrapLines.start; } + if (d->visWrapLines.end + delta > totalWraps) { + /* Don't scroll past the bottom. */ + delta = totalWraps - d->visWrapLines.end; + } + if (d->visWrapLines.start + delta < 0) { + /* Don't ever scroll above the top. */ + delta = -d->visWrapLines.start; + } d->visWrapLines.start += delta; d->visWrapLines.end += delta; iAssert(contains_Range(&d->visWrapLines, cursorY)); @@ -584,6 +595,7 @@ static void updateVisible_InputWidget_(iInputWidget *d) { } // printf("[InputWidget %p] total:%d viswrp:%d cur:%d vis:%d..%d\n", // d, totalWraps, visWraps, d->cursor.y, d->visWrapLines.start, d->visWrapLines.end); +// fflush(stdout); } static void showCursor_InputWidget_(iInputWidget *d) { -- cgit v1.2.3