aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2016-09-21 13:48:56 +0200
committerThomas White <taw@bitwiz.org.uk>2016-09-21 13:48:56 +0200
commitb017dba2f888d7f98b1ca85b62227d78a5ce742a (patch)
tree4612b03bc2f4967d14b0666d471cd654e755ed72 /src
parent4c6aaa1d33d27df0c680cc6c94f221a5ceb9d9e6 (diff)
Keep the cursor inside the window on edit
Diffstat (limited to 'src')
-rw-r--r--src/sc_editor.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/sc_editor.c b/src/sc_editor.c
index 2627b5a..f00ad28 100644
--- a/src/sc_editor.c
+++ b/src/sc_editor.c
@@ -598,6 +598,26 @@ SCBlock *split_paragraph_at_cursor(SCEditor *e)
}
+static void check_cursor_visible(SCEditor *e)
+{
+ double x, y, h;
+
+ get_cursor_pos(e->cursor_frame, e->cursor_para,
+ e->cursor_pos+e->cursor_trail, &x, &y, &h);
+
+ /* Off the bottom? */
+ if ( y - e->scroll_pos + h > e->visible_height ) {
+ e->scroll_pos = y + h - e->visible_height;
+ e->scroll_pos += e->cursor_frame->pad_b;
+ }
+
+ /* Off the top? */
+ if ( y < e->scroll_pos ) {
+ e->scroll_pos = y - e->cursor_frame->pad_t;
+ }
+}
+
+
static void insert_text(char *t, SCEditor *e)
{
Paragraph *para;
@@ -627,8 +647,6 @@ static void insert_text(char *t, SCEditor *e)
cursor_moveh(e->cursor_frame, &e->cursor_para,
&e->cursor_pos, &e->cursor_trail, +1);
- sc_editor_redraw(e);
-
} else {
SCBlock *ad;
@@ -653,9 +671,10 @@ static void insert_text(char *t, SCEditor *e)
/* FIXME: Find the cursor again */
- sc_editor_redraw(e);
}
+ check_cursor_visible(e);
+ sc_editor_redraw(e);
}