summaryrefslogtreecommitdiff
path: root/core/look.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 01:43:24 -0300
committerGabriel Schneider <[email protected]>2026-11-24 01:43:40 -0300
commited05c825102ebce7cd1e314226a1c88b8658baef (patch)
tree41957f9fb7c5df11389d7872079c6494f47af5ce /core/look.zig
parent0252c830daf6184a9faefa32a7d1f384f5a86b94 (diff)
parent59b6ac1bae9cb6720252e1c3e1cc9d4f3a8ab3b1 (diff)
downloadpardes-ed05c825102ebce7cd1e314226a1c88b8658baef.tar.gz
pardes-ed05c825102ebce7cd1e314226a1c88b8658baef.zip
integration: the tree to install next: a view scrolls by ROWS: `main` (pardes-merge66, 0252c830daf6, installed 2026-11-24 01:22) and pardes-row-scroll-3 (`wkxsvmun` on `kyntorlp`, `rymstysv`, `qwssppvo`, on pardes-merge65: a view's top is (line, row within the line's own wrapped rows): a notch is one row through a wrapped line and a wrapped description of the layer, the margin, PageDown/PageUp, `gt`/`gb`, `gw`, `blankRows` and a Look's centring count rows; the wire 35); no conflict; REMOVED HERE: `core/walk.zig.orig`, a patch's leftover that `pvwuwnlk` had added; EXPECTED in its gate and ruled: corpus frame 76 differs (the margin counts rows: the new picture stands) and ten perf counts over tree7 (P85: the view now draws the rows the cursor is on in a wrapped line: deep-sel; the cursor's row found in long lines); its gate: .scratch/sketch/reorg/merge67, the numbers in PARDES.md
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/look.zig')
-rw-r--r--core/look.zig55
1 files changed, 41 insertions, 14 deletions
diff --git a/core/look.zig b/core/look.zig
index 72bb42eb..ee6debf9 100644
--- a/core/look.zig
+++ b/core/look.zig
@@ -499,9 +499,7 @@ pub fn jumpResult(p: *Pardes, id: usize, row: usize) bool {
rp.body.nsel = 0;
rp.body.cur_row = r;
rp.body.cur_pinned = true;
- const off = rp.scroll();
- const last = off + @as(i32, rp.rows) - 1;
- if (r < off) rp.scrollBy(r - off) else if (r > last) rp.scrollBy(r - last);
+ if (rp.file != null) panes.File.show(p.settings.tab, rp, r, 0, 0);
var realbuf: [4096]u8 = undefined;
const span = if (tr.commands)
wholeRowSpan(ln)
@@ -820,14 +818,9 @@ pub fn focusPaneLine(p: *Pardes, id: usize, at_in: Spot, landing: enum { center,
};
if (pane.file) |*f| {
if (at.line > panes.File.nlines(p.gpa, f)) return;
- if (landing == .center) {
- // center, clamp at top; a text that fits is shown whole
- const next = if (pane.textFits()) 0 else (at.line - 1) -| pane.rows / 2;
- if (next != f.scroll) {
- f.scroll = next;
- f.syntax_dirty = true;
- }
- }
+ // centred (its first row of text half the body's rows down, as
+ // zz), clamped at the top; a text that fits is shown whole
+ if (landing == .center) panes.File.setTop(pane, if (pane.textFits()) .{ .line = 0 } else panes.File.walkRows(p.settings.tab, pane, .{ .line = at.line - 1, .row = panes.File.rowOf(p.settings.tab, pane, at.line - 1, 0) }, -@as(i64, pane.rows / 2)).to);
}
pane.body.cur_row = std.math.cast(i32, at.line - 1) orelse return;
pane.body.cur_col = columnOn(pane, pane.body.cur_row, at.col);
@@ -1697,11 +1690,13 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
// miss of its line too.
if (p.fs.failures != failures) return;
layout.compute(p);
- nt.file.?.scroll -|= @max(1, v.rects[free].h -| BOX_H) / 2;
+ // Its line half the body's rows down, a wrapped line's
+ // rows above it counted.
+ const centered = panes.File.walkRows(p.settings.tab, nt, .{ .line = nt.file.?.scroll }, -@as(i64, @max(1, v.rects[free].h -| BOX_H) / 2)).to;
+ panes.File.setTop(nt, centered);
if (target.at.end_line != 0) {
- const centered = nt.file.?.scroll;
selectSpan(p, nt, target.at);
- nt.file.?.scroll = centered;
+ panes.File.setTop(nt, centered);
}
opened = free;
}
@@ -1932,6 +1927,35 @@ test "lookableLineSpan prefers the longest run, so a blank inside a path is one
);
}
+test "a Look that opens a file in a pane of its own puts its line half the body's rows down, a wrapped line's rows above it counted" {
+ const gpa = std.testing.allocator;
+ const io = std.testing.io;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ // Line 10 of 600 bytes, eleven rows or more in a pane 60 wide.
+ var text: std.ArrayList(u8) = .empty;
+ defer text.deinit(gpa);
+ for (0..60) |i| if (i == 10) {
+ try text.appendNTimes(gpa, 'a', 600);
+ try text.append(gpa, '\n');
+ } else try text.print(gpa, "line {d:0>2}\n", .{i});
+ try tmp.dir.writeFile(io, .{ .sub_path = "c.txt", .data = text.items });
+ var buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(io, &buf)];
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 40 });
+ defer p.deinit();
+ p.settings.wrap = true;
+ _ = try p.setTestFile("x\n");
+ var line: [4200]u8 = undefined;
+ p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/c.txt:14", .{dir}) });
+ const id = p.view().active;
+ const pane = p.panes[id].?;
+ try std.testing.expect(panes.File.lineRows(p.settings.tab, pane, 10) >= 11);
+ try std.testing.expectEqual(@as(i32, 13), pane.body.cur_row);
+ const half: i64 = @max(1, p.view().rects[id].h -| BOX_H) / 2;
+ try std.testing.expectEqual(half, panes.File.rowsTo(p.settings.tab, pane, panes.File.top(p.settings.tab, pane), 13, 100).?);
+}
+
test "a miss names a long path by its start and its end, its middle given up to …" {
var cut: [miss_path_cap + "…".len]u8 = undefined;
const long = "/home/someone/" ++ std.mem.asBytes(&@as([80][5]u8, @splat("deep/".*))) ++ "the-file.zig";
@@ -2313,6 +2337,7 @@ test "Look on a diff: headers and a hunk line's prefix are the whole line, hover
// Back to the diff, scrolled to its top again.
p.view().active = 0;
pane.file.?.scroll = 0;
+ pane.file.?.scroll_row = 0;
p.sync();
_ = frame.reset(.retain_capacity);
_ = try p.render(frame.allocator());
@@ -2386,6 +2411,7 @@ test "a click, a 9P whole-line look and an empty event write-back take one expan
for (points) |at| {
p.view().active = 0;
pane.file.?.scroll = 0;
+ pane.file.?.scroll_row = 0;
pane.body.cur_row = 0;
p.sync();
_ = frame.reset(.retain_capacity);
@@ -2462,6 +2488,7 @@ test "every entry point to Look takes one expansion: a diff line and a file:12:5
pane.body.cur_col = case.col;
pane.body.cur_pinned = true;
pane.file.?.scroll = 0;
+ pane.file.?.scroll_row = 0;
p.sync();
_ = frame.reset(.retain_capacity);
_ = try p.render(frame.allocator());