summaryrefslogtreecommitdiff
path: root/core/Query.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 21:10:15 -0300
committerGabriel Schneider <[email protected]>2026-11-24 21:10:17 -0300
commitb28053aede910b8714db4f27ef66e59dd96945c0 (patch)
treea0aea3ca051a21cf3378de5d587357e9208deebb /core/Query.zig
parentabe3817e8dd0af41e6b5786bdbeb631219b58c23 (diff)
downloadpardes-b28053aede910b8714db4f27ef66e59dd96945c0.tar.gz
pardes-b28053aede910b8714db4f27ef66e59dd96945c0.zip
Prompt: `/` and `?` search a file's body as they are typed (walk UI, pick-ui SPEC.md §7.3, item 2 of line E): its places found from where it began (Places.search, the view's on the key, a frame's budget a tick after), tinted, the current one stronger and selected as soon as it is found (`?`: the last before the caret, once the text between is searched), the gutter marked in the blank after each line number (`▸` the current place's line, `▪` the others'), counted `3/7 · 5 lines` (`3/⋯` while they are found; the lines counted once, at the step they are all found, a pass to the last place), ` · wrapped` past the end from where it began, `0` for no match; a pattern that is no regex keeps the last places, dimmed (Places.paint), the reason in the count; Enter lands, the pattern in `/`, and folds the pane's one search word into its trail (`/dirty/ 3/7`, Trail.setWord: the newest back step, in place of the one it had); n and N write it again in place and echo `/dirty/ 4/7 · line 112` on the message row, ` ↻` after a step round an end, `–/7` with the selection off its places, every step (Prompt.settle beside the places'); the first Esc in normal mode clears a search's tints (SPEC §10.4's first step: C's Esc order when it lands) and the word stays, dimmed (draw.zig, Trail.spanOf); Look on the word lights its places again and selects the one it was on, Exec searches again from the caret (Trail.lookStep, execStep); `*` makes the selection's pattern the search word, no prompt and no query pane; Alt-Enter keeps the places as rows: today's query pane (Query.open .text), the body as it was; `?` is helix's backward search, a new role (modal.zig, config.zig); THE FAULTS THE TESTS MET, both B's and latent until a word step was made: Trail.wordOf returned the text of a COPY of the step (a slice of its stack frame: the word drawn as garbage), now the step's own bytes; Trail.lastCur held `cur` under `n`, though keep() leaves a held pane's at `n` (a search word alone: the dump's load moved it and the digests differed), now `n`; TEST FIRST: Prompt.zig "/ searches the body as it is typed ..." and "? searches back from the caret ..."; Places' `*` test reads the echo, Query's and Stream's `/` tests keep their query pane by Alt-Enter, Query's `*` test reads the word; test/perf.zig --search measures a key in `/` and `s` on a 1 MB file; goldens fsearch, lookrange (the prompt in the tag, the word in the trail); core-test 1016/1182 (166 skipped), shell-test 1229/1232, pane-test 182/184, behaviour-test 274/277 (the failures A's, as on item 1), process-test A's six and none of mine, term-test 17/17, kitty-test 45/45
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'core/Query.zig')
-rw-r--r--core/Query.zig24
1 files changed, 15 insertions, 9 deletions
diff --git a/core/Query.zig b/core/Query.zig
index feebb6cd..3ac87dfb 100644
--- a/core/Query.zig
+++ b/core/Query.zig
@@ -2134,6 +2134,12 @@ pub fn paint(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u16)
// ---- tests ----
+/// `/` and `typed` in the tag's prompt, kept as the query pane (Alt-Enter).
+fn slash(p: *Pardes, typed: []const u8) void {
+ typeKeys(p, typed);
+ p.update(.{ .key = .{ .cp = Key.enter, .alt = true } });
+}
+
fn typeKeys(p: *Pardes, text: []const u8) void {
for (text) |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
}
@@ -2169,7 +2175,7 @@ test "a / query: keystroke by keystroke, the owner shows the set, rows from its
// cursor on line 3 (row 2)
pane.body.cur_row = 2;
pane.body.cur_col = 0;
- typeKeys(p, "/");
+ slash(p, "/");
const qid = queryPane(p).?;
const qp = p.panes[qid].?;
try std.testing.expectEqual(@as(?usize, 0), layout.ownerOf(p, qid));
@@ -2226,7 +2232,7 @@ test "a dump holding a query pane, live or frozen, restores it as it was" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 });
defer p.deinit();
_ = try p.setTestFile("alpha one\nbeta\nalphabet\n");
- typeKeys(p, "/alpha");
+ slash(p, "/alpha");
for (0..2) |_| {
const qid = queryPane(p).?;
try pardes.dump.dumpState(p);
@@ -2245,7 +2251,7 @@ test "a / query: Enter lands and freezes, the register filled, n and N step sile
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 });
defer p.deinit();
const pane = try p.setTestFile("alpha one\nbeta\nalphabet\ngamma alpha\nalpha two\ndelta\n");
- typeKeys(p, "/alpha");
+ slash(p, "/alpha");
const qid = queryPane(p).?;
const qp = p.panes[qid].?;
const q = qp.query.?;
@@ -2274,7 +2280,7 @@ test "a / query: Enter lands and freezes, the register filled, n and N step sile
typeKeys(p, "N");
try std.testing.expectEqual(@as(?usize, 3), pane.places.current);
// a later `/` reuses the pane: line 1 fresh, the rows the new query's
- typeKeys(p, "/");
+ slash(p, "/");
try std.testing.expectEqual(qid, queryPane(p).?);
try std.testing.expectEqual(qid, p.view().active);
try std.testing.expect(!q.frozen);
@@ -2419,11 +2425,12 @@ test "* seeds line 1 and keeps the keyboard; SPC b b picks a pane, SPC s s a dec
const pane = try p.setTestFile("const alpha = 1;\nfn beta() void {\n _ = alpha;\n}\nfn gamma() void {}\n");
p.gpa.free(pane.file.?.path);
pane.file.?.path = try p.gpa.dupe(u8, "/tmp/x.zig");
- // `*` on `const`: line 1 `/\bconst\b`, the keyboard still in the text
+ // `*` on `const`: its places and the pane's search word, no query
+ // pane, the keyboard still in the text (Prompt.zig)
typeKeys(p, "e*");
- const qid = queryPane(p).?;
+ try std.testing.expect(queryPane(p) == null);
try std.testing.expectEqual(@as(usize, 0), p.view().active);
- try std.testing.expect(std.mem.startsWith(u8, lineOne(p.panes[qid].?.file.?.content), "/"));
+ try std.testing.expect(pane.trail.n == 1 and pane.trail.steps[0] == .search);
try std.testing.expect(pane.places.started);
typeKeys(p, "n");
try std.testing.expectEqual(@as(?usize, 0), pane.places.current);
@@ -2433,7 +2440,6 @@ test "* seeds line 1 and keeps the keyboard; SPC b b picks a pane, SPC s s a dec
p.view().active = 0;
leader(p, "bb");
const bid = queryPane(p).?;
- try std.testing.expectEqual(bid, qid);
try std.testing.expectEqual(Source.panes, p.panes[bid].?.query.?.source);
try std.testing.expect(p.panes[bid].?.query.?.total >= 1);
// SPC s s: the declarations, fuzzy; Enter lands on the line
@@ -2512,7 +2518,7 @@ test "B1 on a query pane's rows places the caret and selects, nothing else, the
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 });
defer p.deinit();
const pane = try p.setTestFile("alpha one\nbeta\nalphabet\ngamma alpha\nalpha two\ndelta\n");
- typeKeys(p, "/alpha");
+ slash(p, "/alpha");
const qid = queryPane(p).?;
const qp = p.panes[qid].?;
const q = qp.query.?;