summaryrefslogtreecommitdiff
path: root/src/ui/inputwidget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/inputwidget.c')
-rw-r--r--src/ui/inputwidget.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c
index 59bb8331..9b334c36 100644
--- a/src/ui/inputwidget.c
+++ b/src/ui/inputwidget.c
@@ -175,9 +175,9 @@ static void updateCursorLine_InputWidget_(iInputWidget *d) {
175 /* May need to scroll to keep the cursor visible. */ 175 /* May need to scroll to keep the cursor visible. */
176 iWidget *flow = findOverflowScrollable_Widget(w); 176 iWidget *flow = findOverflowScrollable_Widget(w);
177 if (flow) { 177 if (flow) {
178 const iRect rootRect = rect_Root(w->root); 178 const iRect rootRect = { rect_Root(w->root).pos, visibleSize_Root(w->root) };
179 int yCursor = contentBounds_InputWidget_(d).pos.y + 179 int yCursor = contentBounds_InputWidget_(d).pos.y +
180 lineHeight_Text(d->font) * d->cursorLine; 180 lineHeight_Text(d->font) * (int) d->cursorLine;
181 const int margin = lineHeight_Text(d->font) * 3; 181 const int margin = lineHeight_Text(d->font) * 3;
182 if (yCursor < top_Rect(rootRect) + margin) { 182 if (yCursor < top_Rect(rootRect) + margin) {
183 scrollOverflow_Widget(flow, top_Rect(rootRect) + margin - yCursor); 183 scrollOverflow_Widget(flow, top_Rect(rootRect) + margin - yCursor);
@@ -877,7 +877,8 @@ static iInt2 textOrigin_InputWidget_(const iInputWidget *d) { //}, const char *v
877 877
878static size_t coordIndex_InputWidget_(const iInputWidget *d, iInt2 coord) { 878static size_t coordIndex_InputWidget_(const iInputWidget *d, iInt2 coord) {
879 const iInt2 pos = sub_I2(coord, contentBounds_InputWidget_(d).pos); 879 const iInt2 pos = sub_I2(coord, contentBounds_InputWidget_(d).pos);
880 const size_t lineNumber = iMin(pos.y / lineHeight_Text(d->font), (int) size_Array(&d->lines) - 1); 880 const size_t lineNumber = iMin(iMax(0, pos.y) / lineHeight_Text(d->font),
881 (int) size_Array(&d->lines) - 1);
881 const iInputLine *line = line_InputWidget_(d, lineNumber); 882 const iInputLine *line = line_InputWidget_(d, lineNumber);
882 const char *endPos; 883 const char *endPos;
883 tryAdvanceNoWrap_Text(d->font, range_String(&line->text), pos.x, &endPos); 884 tryAdvanceNoWrap_Text(d->font, range_String(&line->text), pos.x, &endPos);