From 9bd34ae2afdb05713f312e7e58dc3d516ea84ebe Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 30 Oct 2026 19:37:42 -0300 Subject: Query: a +Search's rows recoloured are made again (locations.cloneRows, Query.save's copy), never written in place: the rows are a blob (File.State location_rows), whose word a digest keeps by address and a replica's rollback copy pins, so a release session kept the word of their colours before a paint landed (recolor's @memcpy); an edit moved them into dropped_marks with the stale word, a replica that hashed them at another time diverged there (fixer 1's soak: `pane 5.file.dropped_marks`), and a client loading the session's dump hashed the colours it carried and loaded "as another session"; dropped_marks stays in the digest, as an undo back to its text reads it; Stream's test, which a Debug build fails before (`the 82-byte blob ... is not what its kept word was: written in place`) Co-Authored-By: Claude Opus 5.5 --- src/Query.zig | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'src/Query.zig') 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); } } -- cgit v1.3