summaryrefslogtreecommitdiff
path: root/core/Text.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Text.zig')
-rw-r--r--core/Text.zig11
1 files changed, 10 insertions, 1 deletions
diff --git a/core/Text.zig b/core/Text.zig
index 54d69a74..ba544bff 100644
--- a/core/Text.zig
+++ b/core/Text.zig
@@ -339,10 +339,19 @@ pub fn scrollViewMove(t: *Text, tab: u16, text: []const u8, range: modal.Selecti
if (t.what != .body) return;
const w = t.pane() orelse return;
const margin: i32 = @min(config.scroll_off, @divTrunc(@as(i32, w.rows) - 1, 2));
- w.scrollBy(delta);
+ w.scrollBy(tab, delta);
const top = w.scroll();
const last_row: i32 = @intCast(File.textLineCount(t, text) - 1);
const cur = modal.selectionCursor(text, range);
+ // A file's rows are not its lines: a line's first row at the margin,
+ // none (inside a line taller than the body) leaving the cursor be.
+ if (w.file != null) {
+ const snap = File.textRowLine(tab, w, if (delta > 0) margin else File.shownRows(tab, w) - 1 - margin, margin, if (delta > 0) .down else .up) orelse return;
+ const head = File.textLineStart(t, text, @intCast(snap));
+ if (if (delta > 0) head <= cur else head >= cur) return;
+ const anchor = if (t.select) range.anchor else head;
+ return setRange(t, tab, text, 0, .{ .anchor = anchor, .head = head }, false);
+ }
if (delta > 0) {
const snap: i32 = @max(0, @min(top + margin, last_row));
const head = File.textLineStart(t, text, @intCast(snap));