summaryrefslogtreecommitdiff
path: root/src/ghost_io.zig
diff options
context:
space:
mode:
authort <t@tjp.lol>2026-11-25 11:25:00 -0700
committert <t@tjp.lol>2026-11-25 11:25:13 -0700
commit205b1d26b5be40424eace945a73867bdfefe90ce (patch)
tree74f51369662d6d065b218f8ba32bf32760eb4596 /src/ghost_io.zig
parentd85d5e98868a4ee0dda6d3faf666996cdb18f998 (diff)
Anchor ghosts and alternatives to surrounding text, not byte offsets
Ghosted text and alternatives are saved with context from the text around them, so an outside edit no longer sends the whole file to raw Markdown. A ghost with no clear place goes to Overflow. An alternatives group that cannot be matched is dropped; its text is not kept. HTML comments show dimmed in place, with their delimiters hidden until the caret enters them. Ctrl+/ on a comment uncomments it. Comments are left out of Lab and AI requests, except the one an alternatives target sits in. The metadata moves to format v3. Builds before this one show v3 files as raw Markdown, so install this build before saving.
Diffstat (limited to 'src/ghost_io.zig')
-rw-r--r--src/ghost_io.zig7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/ghost_io.zig b/src/ghost_io.zig
index e5061ff..ff9f612 100644
--- a/src/ghost_io.zig
+++ b/src/ghost_io.zig
@@ -37,11 +37,8 @@ pub fn visible(allocator: Allocator, body: []const u8, ghosts: anytype) ![]const
/// owns the returned slice. On failure, keep the original Markdown and metadata
/// intact rather than continuing with a partially decoded document.
///
-/// Offset-only records cannot detect edits that leave all insertion points in
-/// bounds and on codepoint boundaries. In that case restore inserts all text at
-/// the recorded positions, without guessing new ones. To reject such edits,
-/// the caller must verify a separately stored digest of the visible bytes and
-/// fall back to the original Markdown on mismatch.
+/// Offsets alone cannot say whether the visible bytes were edited: the caller
+/// must already know where each ghost belongs in these.
pub fn restore(allocator: Allocator, body_visible: []const u8, ghosts: anytype) ![]const u8 {
if (ghosts.len != 0 and !std.unicode.utf8ValidateSlice(body_visible)) return error.InvalidUtf8;
var removed: usize = 0;