summaryrefslogtreecommitdiff
path: root/src/body_layer.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-24 13:59:21 -0300
committerGabriel Schneider <[email protected]>2026-10-24 15:56:58 -0300
commitce6ba3d8a9e1f5c1e31892639049317f6a27b1bc (patch)
tree939446ce2794e49ba950fa29acfa69292485288f /src/body_layer.zig
parent05d03191a8bfdb7c76176a91fddd97f389ab6dc3 (diff)
downloadpardes-ce6ba3d8a9e1f5c1e31892639049317f6a27b1bc.tar.gz
pardes-ce6ba3d8a9e1f5c1e31892639049317f6a27b1bc.zip
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
Diffstat (limited to 'src/body_layer.zig')
-rw-r--r--src/body_layer.zig22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/body_layer.zig b/src/body_layer.zig
index e50b7e3e..90622e52 100644
--- a/src/body_layer.zig
+++ b/src/body_layer.zig
@@ -73,7 +73,9 @@ fn pastView(pane: *Pane, body: []const u8, line: i32, row: i32, at: i32, col: i3
const from: usize = @intCast(@max(0, at));
const to: usize = @intCast(@max(0, col));
if (from >= text.len) return to >= from +| tw;
- return to >= from + panes.File.byteAtDisplay(text[from..], tw) and to < text.len;
+ // A file row's last shown byte counts its table pads (File.rowPads).
+ const shown: usize = if (pane.file != null) @intCast(panes.File.byteAtRowDisplay(pane, line, at, tw)) else from + panes.File.byteAtDisplay(text[from..], tw);
+ return to >= shown and to < text.len;
}
fn paintSourceSelection(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, rows: []const Pane.PointerRow, bg: [3]u8, fg: ?[3]u8) void {
@@ -95,8 +97,15 @@ fn paintSourceSelection(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, rows: []c
const lo = @max(start, row.lo);
const hi = @min(end, row.hi);
if (lo >= hi) continue;
- const col = prefix + source.pad + @as(i32, @intCast(panes.File.rawDisplayCol(line[start..], lo - start)));
- const last = @min(width, if (row.to_edge and hi == end) @as(i32, width) else prefix + source.pad + @as(i32, @intCast(panes.File.rawDisplayCol(line[start..], hi - start))));
+ // A file row through its pads (File.rowPads), as it is drawn.
+ const col = prefix + source.pad + if (pane.file != null)
+ panes.File.displayOffset(pane, source.line, @intCast(start), @intCast(lo))
+ else
+ @as(i32, @intCast(panes.File.rawDisplayCol(line[start..], lo - start)));
+ const last = @min(width, if (row.to_edge and hi == end) @as(i32, width) else prefix + source.pad + if (pane.file != null)
+ panes.File.displayOffset(pane, source.line, @intCast(start), @intCast(hi))
+ else
+ @as(i32, @intCast(panes.File.rawDisplayCol(line[start..], hi - start))));
if (col < last) s.tint(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(visible)), @intCast(last - col), bg, fg);
}
}
@@ -361,7 +370,12 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
// The byte past the row's last column, walked from its first:
// bounded by the view, not the line.
// A line that ends inside the view has no column past it.
- const shown_to = if (row_at >= row_text.len) row_text.len else row_at + panes.File.byteAtDisplay(row_text[row_at..], tw);
+ const shown_to = if (row_at >= row_text.len)
+ row_text.len
+ else if (pane.file != null)
+ @as(usize, @intCast(panes.File.byteAtRowDisplay(pane, w.line, w.at, tw)))
+ else
+ row_at + panes.File.byteAtDisplay(row_text[row_at..], tw);
const past_view = if (shown_to >= row_text.len) std.math.maxInt(usize) else shown_to;
// A row that ends before the selection starts has none of it.
if (w.line == bnd.lo_row and @as(usize, @intCast(@max(0, bnd.lo_col))) >= past_view) continue;