summaryrefslogtreecommitdiff
path: root/src/Query.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Query.zig')
-rw-r--r--src/Query.zig41
1 files changed, 18 insertions, 23 deletions
diff --git a/src/Query.zig b/src/Query.zig
index 2f417a68..dfe23046 100644
--- a/src/Query.zig
+++ b/src/Query.zig
@@ -372,24 +372,8 @@ fn save(p: *Pardes, rp: *Pane, q: *Query) !Saved {
const f = &rp.file.?;
const content = try p.gpa.dupe(u8, f.content);
errdefer p.gpa.free(content);
- const rows = try p.gpa.alloc(locations.Row, f.location_rows.len);
- var made: usize = 0;
- errdefer {
- for (rows[0..made]) |r| {
- p.gpa.free(r.path);
- p.gpa.free(r.colors);
- }
- p.gpa.free(rows);
- }
- for (f.location_rows, 0..) |r, i| {
- rows[i] = r;
- rows[i].path = try p.gpa.dupe(u8, r.path);
- rows[i].colors = p.gpa.dupe(u8, r.colors) catch |err| {
- p.gpa.free(rows[i].path);
- return err;
- };
- made += 1;
- }
+ const rows = try locations.cloneRows(p.gpa, f.location_rows);
+ errdefer locations.freeRows(p.gpa, rows);
const asked = try p.gpa.dupe(u8, q.asked);
errdefer p.gpa.free(asked);
return .{ .content = content, .rows = rows, .asked = asked, .source = q.source, .items = try p.gpa.dupe(Item, q.items.items), .current = q.current, .total = q.total, .k = q.k };
@@ -865,18 +849,29 @@ pub fn recolor(p: *Pardes) void {
const f = &rp.file.?;
var sh: Shades = .{};
var lines = std.mem.splitScalar(u8, f.content, '\n');
- var changed = false;
- for (f.location_rows) |row| {
+ // The rows are a blob (File.State): a digest keeps its word for
+ // them and a rollback copy pins them, so they are made again, never
+ // written. Written in place, a session's digest kept the word of
+ // their colours before; a client joining hashed them after, and
+ // loaded "as another session" (and so did a replica that hashed them
+ // at another time).
+ var fresh: ?[]locations.Row = null;
+ for (f.location_rows, 0..) |row, i| {
const text = lines.next() orelse break;
if (row.kind != .match or row.location_end == 0 or row.at.line == 0 or row.colors.len == 0) continue;
if (std.mem.indexOfNone(u8, row.colors, &.{0}) != null) continue;
const code = text[@min(row.code_start, text.len)..];
const got = sh.of(p, row.path, row.at.line, code[0..@min(code.len, row.colors.len)], row.source_column);
if (got.len == 0) continue;
- @memcpy(row.colors[0..got.len], got);
- changed = true;
+ const rows = fresh orelse locations.cloneRows(p.gpa, f.location_rows) catch break;
+ 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 (changed) dropHighlights(p, f);
}
}