summaryrefslogtreecommitdiff
path: root/src/Query.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 02:31:20 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitf749eb712d990a9b03f1db372d5311e77bd32edd (patch)
treeee4d9966f1eb293054b7ed865c9d4d6eb49e432b /src/Query.zig
parent8f6621f9f70db86d56266a59b56dfb92b324b0d9 (diff)
parentb3d32656413734952bc918c2d4cfd12fede6c214 (diff)
downloadpardes-f749eb712d990a9b03f1db372d5311e77bd32edd.tar.gz
pardes-f749eb712d990a9b03f1db372d5311e77bd32edd.zip
integration: the terminal behind src/Term.zig, with the diff viewer and the plumber's first phase
A merge of term-phase0 and pardes-next. File.zig's recolorSyntax keeps the theme's grounds and names Term.Filter and Term.Span; the changelog keeps both sides' entries, the palette sentence in the place of the entry the terminal work cut down. core-test 985/985 on tui; the diff, pager and tree process cases pass, goldens unchanged. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src/Query.zig')
-rw-r--r--src/Query.zig62
1 files changed, 36 insertions, 26 deletions
diff --git a/src/Query.zig b/src/Query.zig
index 27b83e1c..4cede3c5 100644
--- a/src/Query.zig
+++ b/src/Query.zig
@@ -859,19 +859,14 @@ fn setRows(p: *Pardes, rp: *Pane, out: *std.ArrayList(u8), rows: *std.ArrayList(
if (std.mem.eql(u8, content, f.content)) {
// Same text: the metadata alone, no undo step, no syntax pass.
p.gpa.free(content);
- if (locations.equalRows(f.location_rows, meta)) {
- locations.freeRows(p.gpa, meta);
- } else {
- locations.freeRows(p.gpa, f.location_rows);
- f.location_rows = meta;
- dropHighlights(p, f);
- }
} else {
File.setContent(p, f, content);
- locations.freeRows(p.gpa, f.location_rows);
- f.location_rows = meta;
f.saved_revision = f.revision;
}
+ File.setRows(p, f, meta) catch |err| {
+ locations.freeRows(p.gpa, meta);
+ if (p.paneBySerial(rp.serial)) |id| p.reportError(id, "rows", err);
+ };
if (f.pager_spans.len > 0) p.gpa.free(f.pager_spans);
f.pager_spans = &.{};
// The cursor stays where it was typing; on a row that went, the last.
@@ -996,24 +991,10 @@ pub fn recolor(p: *Pardes) void {
fresh = rows;
@memcpy(rows[i].colors[0..got.len], got);
}
- if (fresh) |rows| {
- locations.freeRows(p.gpa, f.location_rows);
- f.location_rows = rows;
- dropHighlights(p, f);
- }
+ if (fresh) |rows| File.setRows(p, f, rows) catch locations.freeRows(p.gpa, rows);
}
}
-/// The pane's painted colours let go, so the next frame paints them from
-/// its rows again: with its text the same, a frame would keep the old ones
-/// (refreshHighlights keeps a painting that covers the view).
-fn dropHighlights(p: *Pardes, f: *File.State) void {
- if (f.highlights.len > 0) p.tree_sitter_gpa.free(f.highlights);
- f.highlights = &.{};
- f.highlight_start = 0;
- f.syntax_dirty = true;
-}
-
/// The path a row of pane `tp`'s text says: its file's, or `@pN` for a
/// text that is no file (a list, a scratch).
fn addressOf(arena: std.mem.Allocator, tp: *const Pane) []const u8 {
@@ -1910,8 +1891,10 @@ pub fn cancel(p: *Pardes, id: usize) void {
}
const f = &rp.file.?;
File.setContent(p, f, s.content);
- locations.freeRows(p.gpa, f.location_rows);
- f.location_rows = s.rows;
+ File.setRows(p, f, s.rows) catch |err| {
+ locations.freeRows(p.gpa, s.rows);
+ p.reportError(id, "query", err);
+ };
p.gpa.free(q.asked);
q.asked = s.asked;
q.source = s.source;
@@ -2745,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);
+}