summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 00:39:47 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitdd5aa28c89e2ca31a4cd806d6087ce4ac52398fc (patch)
tree2c79f9311d7dc2b7ef833257cfe260a631496146
parentd7b3d57ed0ba649f01559356fbf2bf89561990ca (diff)
downloadpardes-dd5aa28c89e2ca31a4cd806d6087ce4ac52398fc.tar.gz
pardes-dd5aa28c89e2ca31a4cd806d6087ce4ac52398fc.zip
look: one row address, look.rowAddressAt(pane, row, col): the address a row's producer gave it (a query pane's row on its address, Query.rowAddress) else the one the pane's language reads in the line (a diff's: diffClickIn), with where the row's words start and the address's text; the mouse (exec.operandAt), an empty look written back to `event` (events.expandAt) and a whole line written to `look` (look.lineAddress, was diffLineAddress) each ask it once, where the mouse asked Query.rowAddress and diffClick in turn and the other two asked the diff alone; so a query pane's gutter look reaches events and 9P too (the behaviour change, in the changelog); test: a query row's address from an event written back and from its whole line written to look, its code still words; the diff's look tests and goldens unchanged
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
-rw-r--r--src/CHANGELOG.md7
-rw-r--r--src/Query.zig27
-rw-r--r--src/exec.zig44
-rw-r--r--src/look.zig49
-rw-r--r--src/ninep/events.zig19
5 files changed, 90 insertions, 56 deletions
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md
index a64de8e1..979e566a 100644
--- a/src/CHANGELOG.md
+++ b/src/CHANGELOG.md
@@ -2,6 +2,13 @@
## Unreleased
+- A query pane's row looked at on its address (its gutter) opens the
+ row's place however the look arrives, as a click there always did: an
+ empty look written back to the pane's `event` file, and the whole row
+ written to its `look` file, now take the address the row holds, not a
+ word of its text. A diff's lines answer all three ways through the same
+ one function (`look.rowAddressAt`).
+
- Each pane's directory over 9P has a `rows` file: a line a body row of a
results pane (+Search, +Callstack, +Diff, a language server's list),
where it points (`path`, line, column, the address's end, where its code
diff --git a/src/Query.zig b/src/Query.zig
index c1a89164..4ae57691 100644
--- a/src/Query.zig
+++ b/src/Query.zig
@@ -2728,3 +2728,30 @@ test "a row's address is the shortest path a Look from the query pane resolves:
} else return error.TestUnexpectedResult;
}
}
+
+test "a query row's address reaches every way a look arrives: an empty look written back to event and the whole row written to look, as the mouse on it" {
+ if (!filesystem.platform_has_fs) return;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 48 });
+ defer p.deinit();
+ const a = try testFileIn(p, &tmp, "a.txt", "zero\none needle\ntwo\nthree needle here\n");
+ leader(p, "fg");
+ typeKeys(p, "needle");
+ settle(p);
+ const qid = queryPane(p).?;
+ const qp = p.panes[qid].?;
+ const f = &qp.file.?;
+ const at = std.mem.indexOf(u8, f.content, "\na.txt:4:7").? + 1;
+ const line = f.content[at..std.mem.indexOfScalarPos(u8, f.content, at, '\n').?];
+ // an empty look written back, on the address: the row's address whole,
+ // its path as the row keeps it
+ try std.testing.expect(std.mem.endsWith(u8, @import("ninep/events.zig").expandAt(p, qp, f.content, at + 3, true, true), "/a.txt:4:7"));
+ // on its code: the word there
+ try std.testing.expectEqualStrings("three", @import("ninep/events.zig").expandAt(p, qp, f.content, at + line.len - "three needle here".len + 1, true, true));
+ // the whole row written to the pane's look: the place
+ a.body.cur_row = 0;
+ const tree = @import("ninep/tree.zig");
+ try std.testing.expectEqual(tree.Status.ok, @import("ninep/testing.zig").wr(p, tree.Node.of(qp.serial, .look), line).reply.status);
+ try std.testing.expectEqual(@as(i32, 3), a.body.cur_row);
+}
diff --git a/src/exec.zig b/src/exec.zig
index df578d08..be8dc46b 100644
--- a/src/exec.zig
+++ b/src/exec.zig
@@ -165,44 +165,30 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l
return result;
}
}
- // In a diff, a file or hunk header, and a hunk line pointed at on its
- // `+`/`-`/` ` prefix, expand to the whole line (the hover shows it) and
- // the look is of the address it names (look.diffAddress), a regular
- // look from there. A hunk line's code is words, looked at as ever:
- // the code's, the prefix never one of them.
- // A query pane's row pointed at on its gutter (its line number): the
- // look is of the row's address (Query.rowAddress), as a +Diff line's
- // prefix is its place; the row's code is words, looked at as ever.
- if (for_look and pane.query != null and clicked.r0 >= pane.tag_rows and clicked.r0 == clicked.r1 and clicked.c0 == clicked.c1 and row >= 0 and col >= 0) gutter: {
- var address_buf: [4096 + 32]u8 = undefined;
- const address = panes.Query.rowAddress(pane, @intCast(row), @intCast(col), &address_buf) orelse break :gutter;
- const meta = pane.file.?.location_rows[@intCast(row)];
- result.text = p.scratch.allocator().dupe(u8, address) catch break :gutter;
- result.file_word = .{ .row = row, .lo = 0, .hi = @intCast(meta.location_end) };
- const expanded = fileWordCells(pane, clicked, row, 0, @intCast(meta.location_end)) orelse return result;
- result.preview = expanded;
- result.expanded = expanded;
- return result;
- }
+ // A row that names an address (look.rowAddressAt), pointed at on it: a
+ // query pane's row on its address (its gutter), a diff's file or hunk
+ // header anywhere, a hunk line on its `+`/`-`/` ` prefix. It expands
+ // to the address's text (the hover shows it) and the look is of the
+ // address, a regular look from there. A row's code is words, looked at
+ // as ever: the code's, the prefix never one of them. A click left of a
+ // query pane's text is no part of its row.
var word_from: usize = 0;
- if (for_look and clicked.r0 >= pane.tag_rows and clicked.r0 == clicked.r1 and clicked.c0 == clicked.c1 and row >= 0) diff: {
+ if (for_look and clicked.r0 >= pane.tag_rows and clicked.r0 == clicked.r1 and clicked.c0 == clicked.c1 and row >= 0 and (col >= 0 or pane.query == null)) row_address: {
var address_buf: [4096 + 32]u8 = undefined;
- const at: usize = @intCast(row);
- const click = look.diffClick(p, pane, at, @intCast(@max(0, col)), &address_buf) orelse break :diff;
- const address = click.address orelse {
- word_from = click.word_from;
- break :diff;
+ const got = look.rowAddressAt(p, pane, @intCast(row), @intCast(@max(0, col)), &address_buf) orelse break :row_address;
+ const address = got.address orelse {
+ word_from = got.word_from;
+ break :row_address;
};
- const line = (look.diffLines(p, pane) orelse break :diff)[at];
- result.text = p.scratch.allocator().dupe(u8, address) catch break :diff;
- const hi = std.math.cast(i32, line.len) orelse return result;
+ result.text = p.scratch.allocator().dupe(u8, address) catch break :row_address;
+ const hi = std.math.cast(i32, got.end) orelse return result;
if (hi == 0) return result;
var expanded = clicked;
if (pane.file != null) {
result.file_word = .{ .row = row, .lo = 0, .hi = hi };
expanded = fileWordCells(pane, clicked, row, 0, hi) orelse return result;
} else {
- const shown = if (raw) raw_line else line;
+ const shown = if (raw) raw_line else got.line;
expanded.c0 = 0;
expanded.c1 = @as(i32, @intCast(panes.File.rawDisplayCol(shown, shown.len))) - 1;
}
diff --git a/src/look.zig b/src/look.zig
index 082565ed..ab77773f 100644
--- a/src/look.zig
+++ b/src/look.zig
@@ -1390,18 +1390,32 @@ pub fn diffAddress(pane: *const Pane, lines: []const []const u8, row: usize, buf
return target.address(buf);
}
-/// What a click at byte `col` of line `row` of a diff pane takes, the one
-/// answer for every way a click arrives (a mouse click, a 9P look of the
-/// whole line, an empty look or exec written back to `event`): a file or
-/// hunk header anywhere, or a hunk line on its `+`/`-`/` ` prefix, is the
-/// address the line names (diffAddress); a hunk line's code is words, from
-/// `word_from` on, the prefix never one of them. Null when the pane shows
-/// no diff or the line is no part of one.
-pub const DiffClick = struct { address: ?[]const u8 = null, word_from: usize = 0 };
+/// What a click at byte `col` of line `row` of a diff pane takes: a file
+/// or hunk header anywhere, or a hunk line on its `+`/`-`/` ` prefix, is
+/// the address the line names (diffAddress); a hunk line's code is words,
+/// from `word_from` on, the prefix never one of them. Null when the line is
+/// no part of a diff.
+const DiffClick = struct { address: ?[]const u8 = null, word_from: usize = 0 };
-pub fn diffClick(p: *Pardes, pane: *Pane, row: usize, col: usize, buf: []u8) ?DiffClick {
+/// What a click at byte `col` of row `row` takes, the one answer for every
+/// way a click arrives (the mouse, exec.operandAt; an empty look written
+/// back to `event`, events.expandAt; a whole line written to `look`): the
+/// address a row's producer gave it (a query pane's row on its address,
+/// Query.rowAddress), else the one the pane's language reads in the line (a
+/// diff's: diffClickIn); or where its words start, the address no part of
+/// them. `line` is the row's text it was read from, and the address's text
+/// in it ends at `end`. Null for a row that names no address.
+pub const RowAddress = struct { address: ?[]const u8 = null, word_from: usize = 0, line: []const u8, end: usize };
+
+pub fn rowAddressAt(p: *Pardes, pane: *Pane, row: usize, col: usize, buf: []u8) ?RowAddress {
+ if (panes.Query.rowAddress(pane, row, col, buf)) |address| {
+ const f = &pane.file.?;
+ return .{ .address = address, .line = modal.lineSlice(f.content, row), .end = f.location_rows[row].location_end };
+ }
const lines = diffLines(p, pane) orelse return null;
- return diffClickIn(pane, lines, row, col, buf);
+ if (row >= lines.len) return null;
+ const click = diffClickIn(pane, lines, row, col, buf) orelse return null;
+ return .{ .address = click.address, .word_from = click.word_from, .line = lines[row], .end = lines[row].len };
}
fn diffClickIn(pane: *const Pane, lines: []const []const u8, row: usize, col: usize, buf: []u8) ?DiffClick {
@@ -1417,18 +1431,19 @@ fn diffClickIn(pane: *const Pane, lines: []const []const u8, row: usize, col: us
return .{ .address = address };
}
-/// A look written over 9P of a whole line of a diff pane (the cursor's line
-/// first, then the first after it): what a click on its first column takes.
+/// A look written over 9P of a whole line of a pane whose rows name
+/// addresses (a diff's, a query pane's: rowAddressAt), the cursor's line
+/// first, then the first after it: what a click on its first column takes.
/// A blank context line (` `) is a line too.
-fn diffLineAddress(p: *Pardes, pane: *Pane, operand: []const u8, buf: []u8) ?[]const u8 {
+fn lineAddress(p: *Pardes, pane: *Pane, operand: []const u8, buf: []u8) ?[]const u8 {
const text = std.mem.trimEnd(u8, operand, "\r\n");
if (text.len == 0) return null;
- const lines = diffLines(p, pane) orelse return null;
+ const lines = (if (pane.query != null) panes.File.cursorLines(p.scratch.allocator(), pane, &pane.file.?) catch null else diffLines(p, pane)) orelse return null;
const cur: usize = @intCast(@max(0, pane.body.cur_row));
for (0..lines.len) |k| {
const i = (cur + k) % lines.len;
if (std.mem.eql(u8, std.mem.trimEnd(u8, lines[i], "\r"), text))
- return (diffClickIn(pane, lines, i, 0, buf) orelse return null).address;
+ return (rowAddressAt(p, pane, i, 0, buf) orelse return null).address;
}
return null;
}
@@ -1524,7 +1539,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
// A whole line of a diff written over 9P (a context line ` Del`
// included) is a look at the address it names, never the word run.
var diff_buf: [4096 + 32]u8 = undefined;
- const looked: []const u8 = diffLineAddress(p, pane, operand_raw, &diff_buf) orelse looked: {
+ const looked: []const u8 = lineAddress(p, pane, operand_raw, &diff_buf) orelse looked: {
if (config.commandWord(command)) |cmd| {
if (exec.execute(p, id, cmd)) |dst| v.active = dst;
return;
@@ -2331,7 +2346,7 @@ test "a click, a 9P whole-line look and an empty event write-back take one expan
if (at.whole_line) {
const lines = diffLines(p, pane).?;
var buf: [4096 + 32]u8 = undefined;
- const whole = diffLineAddress(p, pane, lines[at.row], &buf) orelse return error.NoWholeLineAddress;
+ const whole = lineAddress(p, pane, lines[at.row], &buf) orelse return error.NoWholeLineAddress;
try std.testing.expectEqualStrings(at.want, whole);
}
}
diff --git a/src/ninep/events.zig b/src/ninep/events.zig
index 77a4e35f..dd9b488c 100644
--- a/src/ninep/events.zig
+++ b/src/ninep/events.zig
@@ -677,22 +677,21 @@ fn scanNumber(data: []const u8, i: *usize, overflow: *bool) ?u32 {
/// What a click at `at` takes, as the mouse's does (exec.operandAt),
/// for an empty range written back: the file name or word under it on its
-/// line (look.expandedWord), else nothing; in a diff pane's body, for a
-/// look alone (`for_look`, exec.operandAt), look.diffClick's answer, the
-/// line's address or its code's words.
+/// line (look.expandedWord), else nothing; in a body whose rows name
+/// addresses, for a look alone (`for_look`, exec.operandAt),
+/// look.rowAddressAt's answer, the row's address or its code's words.
pub fn expandAt(p: *Pardes, pane: *Pane, whole: []const u8, at: usize, in_body: bool, for_look: bool) []const u8 {
const start = if (std.mem.lastIndexOfScalar(u8, whole[0..at], '\n')) |nl| nl + 1 else 0;
const end = std.mem.indexOfScalarPos(u8, whole, at, '\n') orelse whole.len;
var word_from: usize = 0;
- if (in_body and for_look) diff: {
+ if (in_body and for_look) row_address: {
const row = std.mem.count(u8, whole[0..start], "\n");
- // Only when the served line is the one the diff reads there.
- const lines = look.diffLines(p, pane) orelse break :diff;
- if (row >= lines.len or !std.mem.eql(u8, std.mem.trimEnd(u8, lines[row], "\r"), std.mem.trimEnd(u8, whole[start..end], "\r"))) break :diff;
var buf: [4096 + 32]u8 = undefined;
- const click = look.diffClick(p, pane, row, at - start, &buf) orelse break :diff;
- if (click.address) |address| return p.scratch.allocator().dupe(u8, address) catch "";
- word_from = click.word_from;
+ const got = look.rowAddressAt(p, pane, row, at - start, &buf) orelse break :row_address;
+ // Only when the served line is the one the address was read from.
+ if (!std.mem.eql(u8, std.mem.trimEnd(u8, got.line, "\r"), std.mem.trimEnd(u8, whole[start..end], "\r"))) break :row_address;
+ if (got.address) |address| return p.scratch.allocator().dupe(u8, address) catch "";
+ word_from = got.word_from;
}
const line = whole[start..end];
if (at - start < word_from or word_from > line.len) return "";