summaryrefslogtreecommitdiff
path: root/src/lib_editor.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib_editor.zig')
-rw-r--r--src/lib_editor.zig12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lib_editor.zig b/src/lib_editor.zig
index f9149ef0..9bfa5cff 100644
--- a/src/lib_editor.zig
+++ b/src/lib_editor.zig
@@ -384,6 +384,18 @@ pub fn Editor(comptime cap: Capacity) type {
return ed.keep(a, live, .done);
}
+ /// The bytes from `from` to `to` replaced with `with`, as one step
+ /// to undo, the ranges following as an edit moves them (one inside
+ /// the bytes goes to their start). `join`: part of the step before
+ /// it instead, as the frames of a drag after its first, so one undo
+ /// takes the whole drag back.
+ pub fn replace(ed: *Self, a: std.mem.Allocator, from: usize, to: usize, with: []const u8, join: bool) Outcome {
+ std.debug.assert(from <= to and to <= ed.len());
+ const live = ed.thaw(a, null) catch return .{ .refused = .out_of_memory };
+ edit.replaceBytes(live.context(a), &live.text, from, to, with, !join) catch return .{ .refused = .out_of_memory };
+ return ed.keep(a, live, .done);
+ }
+
/// The register `name`'s values, one per range that wrote it.
pub fn register(ed: *const Self, a: std.mem.Allocator, name: u21) error{OutOfMemory}!?[]const []const u8 {
var r: Registers = .{};