aboutsummaryrefslogtreecommitdiff
path: root/view.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-10-03 13:05:51 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-10-03 13:05:51 +0200
commit5aa0a68d3d5af745b97ddec576f0bbfbe18ed2ab (patch)
tree46e601387828285d253f6b08da7339ecf404de06 /view.c
parent2f337a347bf1ec9cfeeb11232ad0fa72d4a9990f (diff)
downloadvis-5aa0a68d3d5af745b97ddec576f0bbfbe18ed2ab.tar.gz
vis-5aa0a68d3d5af745b97ddec576f0bbfbe18ed2ab.tar.xz
vis: improve cursor positioning after scrolling
Make cursor placement after scrolling (half) pages up/down less arbitrary. Close #390, fix #391
Diffstat (limited to 'view.c')
-rw-r--r--view.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/view.c b/view.c
index 8f37dcc..1d620de 100644
--- a/view.c
+++ b/view.c
@@ -738,6 +738,43 @@ size_t view_scroll_up(View *view, int lines) {
return cursor->pos;
}
+size_t view_scroll_page_up(View *view) {
+ Cursor *cursor = view->cursor;
+ if (view->start == 0) {
+ view_cursor_to(view, 0);
+ } else {
+ view_cursor_to(view, view->start-1);
+ view_redraw_bottom(view);
+ view_screenline_begin(cursor);
+ }
+ return cursor->pos;
+}
+
+size_t view_scroll_page_down(View *view) {
+ view_scroll_down(view, view->height);
+ return view_screenline_begin(view->cursor);
+}
+
+size_t view_scroll_halfpage_up(View *view) {
+ Cursor *cursor = view->cursor;
+ if (view->start == 0) {
+ view_cursor_to(view, 0);
+ } else {
+ view_cursor_to(view, view->start-1);
+ view_redraw_center(view);
+ view_screenline_begin(cursor);
+ }
+ return cursor->pos;
+}
+
+size_t view_scroll_halfpage_down(View *view) {
+ size_t end = view->end;
+ size_t pos = view_scroll_down(view, view->height/2);
+ if (pos < text_size(view->text))
+ view_cursor_to(view, end);
+ return view->cursor->pos;
+}
+
size_t view_scroll_down(View *view, int lines) {
Cursor *cursor = view->cursor;
if (view_viewport_down(view, lines)) {