summaryrefslogtreecommitdiff
path: root/src/ninep/pane.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 11:02:29 -0300
committerGabriel Schneider <[email protected]>2026-11-05 13:14:28 -0300
commit8640107e29a940d50a5eef0dc7d12689a515d856 (patch)
tree13eb927f31e34d8b50366b3cabc8491c04debdcb /src/ninep/pane.zig
parent3f1533813b6692a736251e4d467a7f108229ddee (diff)
downloadpardes-8640107e29a940d50a5eef0dc7d12689a515d856.tar.gz
pardes-8640107e29a940d50a5eef0dc7d12689a515d856.zip
text journal, the primitive: File.replace(off, len, bytes) puts an edit in the text's own buffer (its tail moved with @memmove), the buffer grown by an eighth when it must be (State.cap), and moves its line index in place from the edit on (shiftIndex, State.line_cap), so a key, a backspace and a 9P write cost their bytes and what follows them, never a copy of the text (on the 50k-line file, Debug, medians against the base run beside it: edit-char 1105 -> 420 us, edit-twin 930 -> 433, body-2m 8.6 -> 4.7 ms, body-appends 173 -> 79 ms); setContent is the same edit with the caller's whole new text taken as the buffer; a replica's core (its allocator an epoch's, rollback.isEpoch) and a text a join still sends (memory.isPinned) keep their bytes, the edit putting a new buffer in their place as every edit did, so the rollback copy, its pins and the join's blobs work as they were; a pane's event readers hear an edit's span found from the edit (events.editSpan), the one diffSpan found from two texts; tests: 'edited line index equals a rebuilt one' becomes 'a line index shifted in place equals a rebuilt one' (editedLineStarts goes), 'an edit's span is where the texts before and after it differ' is new, and the panes test of history storage counts one allocation less for a redo (the index moves in place)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/ninep/pane.zig')
-rw-r--r--src/ninep/pane.zig6
1 files changed, 1 insertions, 5 deletions
diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig
index 289639e9..ab4b2d7d 100644
--- a/src/ninep/pane.zig
+++ b/src/ninep/pane.zig
@@ -300,14 +300,10 @@ pub fn spliceBody(p: *Pardes, pane: *Pane, q0: usize, q1: usize, bytes: []const
// An empty range deleted, or a range replaced by what it holds: no
// edit, so no undo step and no new revision.
if (std.mem.eql(u8, f.content[lo..hi], bytes[0..take])) return take;
- const new = p.gpa.alloc(u8, f.content.len - (hi - lo) + take) catch return null;
- @memcpy(new[0..lo], f.content[0..lo]);
- @memcpy(new[lo..][0..take], bytes[0..take]);
- @memcpy(new[lo + take ..], f.content[hi..]);
const join = pane.fs.joined == f.revision;
pane.fs.joined = null;
if (!pane.fs.nomark and !join) panes.File.pushUndo(p, pane);
- panes.File.setContentSpan(p, f, new, .{ .head = lo, .tail = f.content.len - hi });
+ if (!panes.File.replace(p, f, lo, hi - lo, bytes[0..take])) return null;
return take;
}