From ce6ba3d8a9e1f5c1e31892639049317f6a27b1bc Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 24 Oct 2026 13:59:21 -0300 Subject: Tables 1/3: a markdown file's pipe tables laid out in their rows, cells padded with virtual width before a byte (a tab's extra cells, not a parallel map): File.rowPads under displayOffset/displayEndOffset/byteAtRowDisplay, fillBody, recolorSyntax, the pointer sweep, j/k; tree-sitter-markdown as the detector's oracle --- src/Text.zig | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/Text.zig') diff --git a/src/Text.zig b/src/Text.zig index 88630f83..b57c953a 100644 --- a/src/Text.zig +++ b/src/Text.zig @@ -514,17 +514,33 @@ pub fn findMove(t: *Text, text: []const u8, range: modal.Selection, ch: u21, fwd setRange(t, text, 0, res, false); } +/// The file pane whose text `text` is, when `t` is its body: its rows are +/// measured through their table pads (File.rowPads), so j and k keep the +/// column a table shows, not the one its source has. +fn filePane(t: *Text, text: []const u8) ?*const Pane { + if (t.what != .body) return null; + const fp = t.pane() orelse return null; + const f = if (fp.file) |*file| file else return null; + return if (f.content.ptr == text.ptr and f.content.len == text.len) fp else null; +} + /// j/k and friends: sticky goal column, clamped onto short lines' newline pub fn verticalMove(t: *Text, text: []const u8, range: modal.Selection, down: bool, cnt: usize) void { const cur = modal.selectionCursor(text, range); const pos = File.textPosition(t, text, cur); + const shown = filePane(t, text); const goal: usize = if (t.sticky_col >= 0) @intCast(t.sticky_col) + else if (shown) |fp| + @intCast(@max(0, File.displayOffset(fp, @intCast(pos.row), 0, @intCast(pos.col)))) else File.rawDisplayCol(File.textLine(t, text, pos.row), pos.col); const last_row = File.textLineCount(t, text) - 1; const nline = if (down) @min(pos.row + @max(1, cnt), last_row) else pos.row -| @max(1, cnt); - const target_col = File.rawAtDisplay(File.textLine(t, text, nline), goal); + const target_col: usize = if (shown) |fp| + @intCast(File.byteAtRowDisplay(fp, @intCast(nline), 0, @intCast(@min(goal, std.math.maxInt(i32))))) + else + File.rawAtDisplay(File.textLine(t, text, nline), goal); const target = File.textOffset(t, text, .{ .row = nline, .col = target_col }); // extend mode never walks onto the empty trailing line (helix) if (t.select and target == text.len and text.len > 0 and text[text.len - 1] == '\n') return; @@ -546,8 +562,11 @@ pub fn visualMove( var row = pos.row; var line = modal.lineSlice(text, row); var vrow = File.visualRow(line, pos.col, width); + const shown = filePane(t, text); const goal: usize = if (t.sticky_col >= 0) @intCast(t.sticky_col) + else if (shown) |fp| + @intCast(@max(0, File.displayOffset(fp, @intCast(row), @intCast(vrow.start), @intCast(pos.col)))) else File.rawDisplayCol(line[vrow.start..vrow.end], pos.col -| vrow.start); var steps = @max(1, cnt); @@ -574,7 +593,10 @@ pub fn visualMove( } // The newline slot is a real cursor position, but the first byte of the // NEXT visual row is not: landing there would read as two rows moved. - var target_col = vrow.start + File.rawAtDisplay(line[vrow.start..vrow.end], goal); + var target_col: usize = if (shown) |fp| + @intCast(File.byteAtRowDisplay(fp, @intCast(row), @intCast(vrow.start), @intCast(@min(goal, std.math.maxInt(i32))))) + else + vrow.start + File.rawAtDisplay(line[vrow.start..vrow.end], goal); if (vrow.end < line.len and target_col >= vrow.end) target_col = modal.graphemeStart(line, vrow.end - 1); const target = File.textOffset(t, text, .{ .row = row, .col = target_col }); -- cgit v1.3