summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2025-11-01 23:03:01 +0100
committerAlbert Cervin <albert@acervin.com>2025-11-01 23:03:01 +0100
commit1ee3b764d7cdd31570e53e446c963725f3a2f962 (patch)
tree1706f1f0fb7828de2238456ca029c9338b2585d1
parent25bac4d2703a0c529b7b97cf86eb07b6264e1242 (diff)
downloaddged-1ee3b764d7cdd31570e53e446c963725f3a2f962.tar.gz
dged-1ee3b764d7cdd31570e53e446c963725f3a2f962.tar.xz
dged-1ee3b764d7cdd31570e53e446c963725f3a2f962.zip
Improve scrolling
Scrolling vertically now keeps two lines of context and overflowing vertically places dot in middle of screen.
-rw-r--r--src/dged/buffer_view.c5
-rw-r--r--src/main/cmds.c26
2 files changed, 25 insertions, 6 deletions
diff --git a/src/dged/buffer_view.c b/src/dged/buffer_view.c
index 9d998fe..9129147 100644
--- a/src/dged/buffer_view.c
+++ b/src/dged/buffer_view.c
@@ -475,8 +475,9 @@ bool buffer_view_update(struct buffer_view *view,
if (view->dot.col >= view->scroll.col + width ||
view->dot.col < view->scroll.col) {
- view->scroll.col =
- buffer_clamp(view->buffer, view->dot.line, view->dot.col).col;
+ view->scroll.col = buffer_clamp(view->buffer, view->dot.line,
+ (int64_t)view->dot.col - params->width / 2)
+ .col;
}
timer_stop(render_linenumbers_timer);
diff --git a/src/main/cmds.c b/src/main/cmds.c
index 7d63661..fa3ceaa 100644
--- a/src/main/cmds.c
+++ b/src/main/cmds.c
@@ -22,6 +22,7 @@
#include "completion/buffer.h"
#include "completion/command.h"
#include "completion/path.h"
+#include "dged/window.h"
#include "search-replace.h"
static void (*g_terminate_cb)(void) = NULL;
@@ -626,8 +627,15 @@ static int32_t scroll_up_cmd(struct command_ctx ctx, int argc,
(void)argc;
(void)argv;
- buffer_view_backward_nlines(window_buffer_view(ctx.active_window),
- window_height(ctx.active_window) - 1);
+ uint32_t height = window_height(ctx.active_window);
+ uint32_t amount = height;
+ if (height > 3) {
+ amount = height - 3;
+ }
+
+ struct buffer_view *bv = window_buffer_view(ctx.active_window);
+ buffer_view_backward_nlines(bv, amount);
+ bv->scroll.line = bv->dot.line;
return 0;
}
@@ -636,8 +644,18 @@ static int32_t scroll_down_cmd(struct command_ctx ctx, int argc,
(void)argc;
(void)argv;
- buffer_view_forward_nlines(window_buffer_view(ctx.active_window),
- window_height(ctx.active_window) - 1);
+ uint32_t height = window_height(ctx.active_window);
+ uint32_t amount = height;
+ if (height > 3) {
+ amount = height - 3;
+ }
+
+ struct buffer_view *bv = window_buffer_view(ctx.active_window);
+ buffer_view_forward_nlines(bv, amount);
+ if (bv->dot.line < buffer_num_lines(bv->buffer)) {
+ bv->scroll.line = bv->dot.line;
+ }
+
return 0;
}