diff options
Diffstat (limited to 'core/Text.zig')
| -rw-r--r-- | core/Text.zig | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/core/Text.zig b/core/Text.zig index 1b3e6273..54d69a74 100644 --- a/core/Text.zig +++ b/core/Text.zig @@ -458,15 +458,17 @@ pub const Journal = struct { j.done = j.steps.items.len; } - /// The `len` bytes of `text` at `off` about to be replaced by `ins` - /// bytes, kept in the last step: in its last entry when they touch it + /// `removed`, the bytes at `off` about to be replaced by `ins` bytes + /// (a file's text's offset: a buffer's read-only lines are none of it, + /// File.fileOffset), kept in the last step: in its last entry when they touch it /// (typing on, deleting what was typed or what borders it, a write /// going on where the last ended), else as an entry of its own. The /// steps to redo go, made on the text before it; an edit with no step to /// go in (before the first mark, or with every step undone) is kept by /// none. On no memory the journal empties: its entries would no longer /// be the text's. - pub fn record(j: *Journal, gpa: std.mem.Allocator, text: []const u8, off: usize, len: usize, ins: usize) void { + pub fn record(j: *Journal, gpa: std.mem.Allocator, removed_bytes: []const u8, off: usize, ins: usize) void { + const len = removed_bytes.len; if (len == 0 and ins == 0) return; j.dropRedo(gpa); if (j.done == 0) return; @@ -485,7 +487,7 @@ pub const Journal = struct { const before = off + len == last.off; if (ins == 0 and (before or off == last.off + last.ins)) { const more = memory.unfilled(gpa, last.removed.len + len) catch return j.deinit(gpa); - const taken = text[off..][0..len]; + const taken = removed_bytes; if (before) { @memcpy(more[0..len], taken); @memcpy(more[len..], last.removed); @@ -500,7 +502,7 @@ pub const Journal = struct { return j.bound(gpa); } } - const removed = memory.dupeUnfilled(gpa, text[off..][0..len]) catch return j.deinit(gpa); + const removed = memory.dupeUnfilled(gpa, removed_bytes) catch return j.deinit(gpa); j.entries.append(gpa, .{ .off = off, .removed = removed, .ins = ins }) catch { memory.freeRaw(gpa, removed); return j.deinit(gpa); |
