summaryrefslogtreecommitdiff
path: root/src/File.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/File.zig')
-rw-r--r--src/File.zig13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/File.zig b/src/File.zig
index 90711c9a..05e5271c 100644
--- a/src/File.zig
+++ b/src/File.zig
@@ -64,7 +64,7 @@ pub const State = struct {
/// What the replay digest leaves out (src/walk.zig): what is made again
/// from the text whenever it is wanted.
pub const replica = .{
- .derived = .{ "cap", "line_starts", "line_cap", "highlights", "highlight_start", "syntax_dirty", "node_tree", "node_tree_revision", "node_history", "tables" },
+ .derived = .{ "cap", "line_starts", "line_cap", "highlights", "highlight_start", "syntax_dirty", "node_tree", "node_tree_revision", "node_tree_edits", "node_history", "tables" },
// Big texts, dumped and sent by their hash (src/walk.zig). The
// text is written in place by `replace`, but never while a join
// sends it (memory.zig `pin`): then an edit puts a new buffer in
@@ -143,6 +143,10 @@ pub const State = struct {
/// one: `syntax.parseTree`'s, opaque here.
node_tree: ?*anyopaque = null,
node_tree_revision: u32 = 0,
+ /// The revision the tree's edits reach (`syntax.editTree`, told by
+ /// `edit` below): at `revision`, the next parse reuses it; else, a
+ /// revision it was not told of (a twin's edit, a reload), a parse anew.
+ node_tree_edits: u32 = 0,
/// helix's object_selections: what Alt-o grew from, for Alt-i to go back
/// to; gpa-owned ranges and the primary's index.
node_history: std.ArrayList(NodeStep) = .empty,
@@ -686,6 +690,13 @@ fn edit(p: *Pardes, f: *State, off: usize, len: usize, bytes_in: []const u8, who
f.saved_hash = std.hash.Wyhash.hash(0, f.content);
f.saved_len = f.content.len;
}
+ // The kept tree follows the edit (normal.fileTree parses with it), but
+ // not while a rollback copy holds it: an edit in place would change the
+ // copy's tree under it, so that one is left as it is and parsed anew.
+ if (f.node_tree) |tree| if (syntax.held_trees == null and f.node_tree_edits == f.revision) {
+ syntax.editTree(tree, f.content[0..off], f.content[off..][0..len], bytes);
+ f.node_tree_edits = f.revision +% 1;
+ };
var undo_gone = false;
if (fresh) |new| {
const old = textRoom(f);