diff options
Diffstat (limited to 'core/Text.zig')
| -rw-r--r-- | core/Text.zig | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/core/Text.zig b/core/Text.zig index 54d69a74..37feb081 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)); @@ -417,6 +426,8 @@ pub const Place = struct { /// (`entries[first..][0..n]`), and the places at its edges: an undo goes /// back to `before`, a redo to `after`, where it was undone from. pub const Step = struct { + /// Its entries are the journal's (walk.zig `.index`, a span). + pub const replica = .{ .index = .{.{ "first", Journal, "entries", "n" }} }; first: usize, n: usize = 0, before: Place, @@ -429,12 +440,26 @@ pub const Step = struct { /// limits.undo_max steps and limits.undo_bytes of what they hold, the /// oldest step dropped first and the newest kept whatever its size. pub const Journal = struct { + /// `done` held to its steps, `bytes` to what its entries hold (walk.zig + /// `.place`). + pub const replica = .{ .place = .{ .{ "done", "stepCount" }, .{ "bytes", "entryBytes" } } }; steps: std.ArrayList(Step) = .empty, done: usize = 0, entries: std.ArrayList(Entry) = .empty, /// What the entries hold: the bytes they took out, and their own size. bytes: usize = 0, + pub fn stepCount(j: *const Journal) usize { + return j.steps.items.len; + } + + /// What `bytes` says, its one place: what the entries hold. + pub fn entryBytes(j: *const Journal) [2]usize { + var n: usize = 0; + for (j.entries.items) |e| n +|= held(e); + return .{ n, n }; + } + pub fn deinit(j: *Journal, gpa: std.mem.Allocator) void { for (j.entries.items) |e| free(gpa, e); j.entries.deinit(gpa); |
