From 4a28a3b182ffafc311982098fd0669e1154fa90b Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 19 Apr 2018 12:57:01 -0400 Subject: [PATCH] implemented first pass at scroll up and down. Still broken for wrapped lines --- lib/config.c | 4 ++-- lib/view.c | 7 +++++++ lib/x11.c | 10 ++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/config.c b/lib/config.c index 4d21dec..1681afa 100644 --- a/lib/config.c +++ b/lib/config.c @@ -8,7 +8,7 @@ #define FONT "Verdana:size=10" #define LNSPACE 0 #else - #define FONT "Liberation Mono:size=11" + #define FONT "Verdana:size=11" #define LNSPACE 1 #endif @@ -22,7 +22,7 @@ int /* Integer config options */ LineSpacing = LNSPACE, Timeout = 50, TabWidth = 4, - ScrollBy = 4, + ScrollBy = 1, ClickTime = 500, MaxScanDist = 0, Syntax = ON, diff --git a/lib/view.c b/lib/view.c index c7b043e..00d210e 100644 --- a/lib/view.c +++ b/lib/view.c @@ -285,6 +285,10 @@ char* view_getctx(View* view) { } static void scroll_up(View* view) { + if (view->index > 0) + view->index--; + else if (view->rows[0]->off > 0) + resize(view, view->width, view->nrows, (view->rows[0]->off - 1)); } static void scroll_dn(View* view) { @@ -295,6 +299,9 @@ static void scroll_dn(View* view) { } else { view->index++; } + + printf("%ld <= %ld\n", view->nvisible, (view->nrows - view->index)); + assert(view->nvisible <= (view->nrows - view->index)); } void view_scroll(View* view, int move) { diff --git a/lib/x11.c b/lib/x11.c index 535dcdf..6de77f5 100644 --- a/lib/x11.c +++ b/lib/x11.c @@ -246,8 +246,14 @@ static void mouse_click(int btn, bool pressed, int x, int y) { case MouseLeft: mouse_left(Focused, pressed, row, col); break; case MouseMiddle: mouse_middle(Focused, pressed, row, col); break; case MouseRight: mouse_right(Focused, pressed, row, col); break; - case MouseWheelUp: view_scroll(win_view(Focused), -ScrollBy); break; - case MouseWheelDn: view_scroll(win_view(Focused), +ScrollBy); break; + case MouseWheelUp: + if (!pressed) return; + view_scroll(win_view(Focused), -ScrollBy); + break; + case MouseWheelDn: + if (!pressed) return; + view_scroll(win_view(Focused), +ScrollBy); + break; } } -- 2.49.0