summaryrefslogtreecommitdiff
path: root/src/Query.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-24 13:11:11 -0300
committerGabriel Schneider <[email protected]>2026-10-24 13:27:54 -0300
commit9299281492d63e549ab274034efb59ab4e9d96f6 (patch)
tree326e55f07d422adf7fd4e9037107c22bfe70ae6e /src/Query.zig
parent1af098381515fbe3a4fe678cd023c7fd74418ae1 (diff)
downloadpardes-9299281492d63e549ab274034efb59ab4e9d96f6.tar.gz
pardes-9299281492d63e549ab274034efb59ab4e9d96f6.zip
Search converge 6/6: SearchPlace column, the finder column at the right edge holding the query panes; n/N in a frozen query pane; the design doc
Diffstat (limited to 'src/Query.zig')
-rw-r--r--src/Query.zig27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/Query.zig b/src/Query.zig
index 3a75a7f5..6374ce42 100644
--- a/src/Query.zig
+++ b/src/Query.zig
@@ -257,6 +257,7 @@ pub fn open(p: *Pardes, from: usize, source: Source, arg: []const u8, focus: boo
const new = std.mem.concat(p.gpa, u8, &.{ line, "\n" }) catch return;
File.setContent(p, f, new);
q.reset(p);
+ if (p.finder.column(p)) |fc| if (layout.findPane(p, id)) |at| if (at.col == fc) p.finder.raise(p, id);
if (rp.collapsed) layout.toggleCollapse(p, id);
// A source that previews gets its +Preview now, at the key that
// asked, not under the typing later.
@@ -318,8 +319,11 @@ fn create(p: *Pardes, owner_id: usize, line: []const u8, source: Source) ?usize
}
}
if (p.settings.search_place == .column) {
- // The finder column (phase 6): until it exists, under the owner.
- if (!layout.attach(p, owner_id, free, want)) exec.placeNew(p, owner_id, owner_id, free, .doc);
+ // On top of the finder column at the right edge (Finder.zig), the
+ // older query panes folded under it; its preview under it there.
+ if (!p.finder.place(p, free) and !layout.attach(p, owner_id, free, want)) exec.placeNew(p, owner_id, owner_id, free, .doc);
+ if (with_preview) _ = makePreview(p, free, p.rects[free].h / 2, free);
+ return free;
} else if (!layout.attach(p, owner_id, free, want)) {
// An owner too short to give a query pane its rows: placed as any
// new pane is, the one place a search moves another pane.
@@ -1727,8 +1731,11 @@ pub fn cancel(p: *Pardes, id: usize) void {
if (owner_id) |oid| p.active = oid;
return;
}
+ // Attached, its rows go back to its owner; in the finder column, to its
+ // own column's.
+ const attached = layout.ownerOf(p, id) != null;
if (owner_id) |oid| {
- p.removePane(id, oid) catch {};
+ p.removePane(id, if (attached) oid else null) catch {};
p.active = oid;
if (layout.findPane(p, oid)) |at| p.setActiveColumn(at.col);
} else p.removePane(id, null) catch {};
@@ -1772,7 +1779,9 @@ pub fn key(p: *Pardes, id: usize, k: Key) bool {
const q = rp.query orelse return false;
if (rp.focus != .body) return false;
const t = &rp.body;
- if (q.frozen) return false;
+ // Normal mode, live or frozen: n and N step the rows (the current one
+ // shown where it points, the keyboard staying), Enter on a hit row lands
+ // on it, as Enter typing does.
if (t.mode == .normal) {
if (t.normal.prefix != .none or k.ctrl or k.alt or t.normal.count != 0) return false;
if (k.cp == 'n' or k.cp == 'N') {
@@ -1780,11 +1789,14 @@ pub fn key(p: *Pardes, id: usize, k: Key) bool {
return true;
}
if (hit(k, config.look_key) and t.cur_row > 0) {
- land(p, id, @intCast(t.cur_row - 1));
+ const i: usize = @intCast(t.cur_row - 1);
+ if (i >= q.items.items.len or q.items.items[i].kind != .hit) return false;
+ land(p, id, i);
return true;
}
return false;
}
+ if (q.frozen) return false;
if (t.cur_row != 0 or t.mode != .insert or t.reg_wait) return false;
if (hit(k, config.escape)) {
cancel(p, id);
@@ -2003,6 +2015,11 @@ test "a / query: Enter lands and freezes, the register filled, n and N step sile
defer std.testing.allocator.free(frozen);
// the rows: one a line (gamma alpha has one), a gutter number each
try std.testing.expect(std.mem.indexOf(u8, frozen, " 1 alpha one\n") != null);
+ // B3 on a row's line number is its address; on its code, no address
+ var abuf: [256]u8 = undefined;
+ const addr = rowAddress(qp, 1, 2, &abuf).?;
+ try std.testing.expect(std.mem.endsWith(u8, addr, ":1:1"));
+ try std.testing.expect(rowAddress(qp, 1, qp.file.?.location_rows[1].code_start + 1, &abuf) == null);
// n and N in the owner step the same set, round the end silently
const logged = p.messages.len;
try std.testing.expectEqual(@as(?usize, 0), pane.places.current);