diff options
Diffstat (limited to 'core/Query.zig')
| -rw-r--r-- | core/Query.zig | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/core/Query.zig b/core/Query.zig index 4fbd07e0..a090929a 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -2147,6 +2147,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} } }); } @@ -2182,7 +2188,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)); @@ -2239,7 +2245,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); @@ -2258,7 +2264,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.?; @@ -2287,7 +2293,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); @@ -2337,6 +2343,8 @@ test "Find: names fuzzy per keystroke, the group born with its +Preview, nothing try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = "pub fn split() void {}\nconst x = 1;\n" }); const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 48 }); defer p.deinit(); + // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6). + p.settings.jumps = .@"new-pane"; _ = try testFileIn(p, &tmp, "x.txt", "x\n"); p.newScratchBelow(0); const other = p.view().cols[0].panes[1]; @@ -2386,6 +2394,8 @@ test "Grep: lines of the files under the owner's directory, under their file; Al try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.zig", .data = "const needle = 1;\nconst hay = 2;\nneedle needle\n" }); const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 48 }); defer p.deinit(); + // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6). + p.settings.jumps = .@"new-pane"; const a = try testFileIn(p, &tmp, "a.txt", "one needle\ntwo\n"); leader(p, "fg"); const qid = queryPane(p).?; @@ -2429,14 +2439,17 @@ test "* seeds line 1 and keeps the keyboard; SPC b b picks a pane, SPC s s a dec if (comptime !syntax.minimal_grammars) return error.SkipZigTest; const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 48 }); defer p.deinit(); + // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6). + p.settings.jumps = .@"new-pane"; 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); @@ -2446,7 +2459,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 @@ -2494,7 +2506,7 @@ test "a language server's list: one answer lands with no pane, several open the p.lspRequest(0, .diagnostics, ""); p.update(.{ .lsp_resp = .{ .id = p.lsp_ask.wait.?.id, .rows = "" } }); try std.testing.expectEqual(@as(usize, 1), npanes(p)); - try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "none") != null); + try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(pane), "none") != null); // Several: the list open, the keyboard in it in normal mode on the // current row, which the text shows; line 1 as text. pane.body.cur_row = 0; @@ -2525,7 +2537,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.?; @@ -2584,6 +2596,8 @@ test "B1 on a query pane's rows places the caret and selects, nothing else, the test "Enter on a frozen query pane's rows after its text was edited: no row to land on, the keyboard to its owner" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); defer p.deinit(); + // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6). + p.settings.jumps = .@"new-pane"; _ = try p.setTestFile("alpha\n"); p.newScratchBelow(0); p.view().active = 0; @@ -2607,6 +2621,8 @@ test "a query row's place is its text: the match tinted after it, B3 on it opens defer tmp.cleanup(); const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 48 }); defer p.deinit(); + // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6). + p.settings.jumps = .@"new-pane"; const a = try testFileIn(p, &tmp, "a.txt", "zero\none needle\ntwo\nthree needle here\n"); leader(p, "fg"); typeKeys(p, "needle"); @@ -2668,6 +2684,8 @@ test "the +Preview: the query's hits in its file are its places, the row's one c try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.zig", .data = text }); const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 60 }); defer p.deinit(); + // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6). + p.settings.jumps = .@"new-pane"; _ = try testFileIn(p, &tmp, "a.txt", "x\n"); leader(p, "fg"); typeKeys(p, "needle"); @@ -2752,6 +2770,8 @@ test "a query row's address reaches every way a look arrives: an empty look writ defer tmp.cleanup(); const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 48 }); defer p.deinit(); + // About a jump opening a pane: `Jumps new-pane` (SPEC §6.6). + p.settings.jumps = .@"new-pane"; const a = try testFileIn(p, &tmp, "a.txt", "zero\none needle\ntwo\nthree needle here\n"); leader(p, "fg"); typeKeys(p, "needle"); |
