From 18d89dcedaed1f8437799621675e88ca47d7cdc1 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 24 Oct 2026 10:29:10 -0300 Subject: Search converge 2/6: a pane's places, every match or listed place tinted and ticked on the rail, n/N stepping them silently, shifted by an edit rather than searched again --- src/File.zig | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/File.zig') diff --git a/src/File.zig b/src/File.zig index b1a4271f..3db22f95 100644 --- a/src/File.zig +++ b/src/File.zig @@ -184,6 +184,10 @@ pub const State = struct { /// One tree_sitter_gpa-owned syntax.Syn byte per highlighted source byte. highlights: []u8 = &.{}, location_rows: []locations.Row = &.{}, + /// The last edit's splice: what the text at `revision` kept of the one + /// before it at either end (`old_len` long). A pane's places shift by it + /// rather than search the whole text again (Places.shift). + splice: struct { revision: u32 = 0, head: usize = 0, tail: usize = 0, old_len: usize = 0 } = .{}, highlight_start: usize = 0, syntax_dirty: bool = true, tree_context: bool = false, @@ -1187,7 +1191,10 @@ pub fn setContentSpan(p: *Pardes, f: *State, new: []u8, span_in: ?Span) void { reportEdit(p, f, new); if (f.mini) |*mini| mini.deinit(p.gpa); f.mini = null; - const starts: []usize = if (f.line_starts.len > 0) editedLineStarts(p.gpa, f.line_starts, f.content, new, span) catch &.{} else &.{}; + // Found once for the line index and the places both (32 bytes a step). + const known = span orelse spanOf(f.content, new); + const starts: []usize = if (f.line_starts.len > 0) editedLineStarts(p.gpa, f.line_starts, f.content, new, known) catch &.{} else &.{}; + const old_len = f.content.len; // ponytail: a whole-text hash per edit that keeps the saved length; a // rolling hash when that too matters. if (f.revision == f.saved_revision or f.saved_hash == null) { @@ -1199,6 +1206,7 @@ pub fn setContentSpan(p: *Pardes, f: *State, new: []u8, span_in: ?Span) void { if (f.content.len > 0) p.gpa.rawFree(f.content, .of(u8), @returnAddress()); f.content = new; f.revision +%= 1; + f.splice = .{ .revision = f.revision, .head = known.head, .tail = known.tail, .old_len = old_len }; if (f.saved_hash) |h| if ((f.saved_len orelse new.len) == new.len and std.hash.Wyhash.hash(0, new) == h) { f.saved_revision = f.revision; }; -- cgit v1.3