diff options
Diffstat (limited to 'src/edit.zig')
| -rw-r--r-- | src/edit.zig | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/src/edit.zig b/src/edit.zig index 4b0e59fe..4a48cfd4 100644 --- a/src/edit.zig +++ b/src/edit.zig @@ -17,19 +17,19 @@ const syntax = @import("syntax.zig"); const indents = @import("indent.zig"); const platform = pardes.platform; const Pane = panes.Pane; -const Text = panes.Text; +const Text = @import("Text.zig"); const Layer = @import("Layer.zig"); const TagHit = pardes.TagHit; const BOX_H = pardes.BOX_H; const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET; const Mouse = pardes.Mouse; -const Key = pardes.Key; -const hit = pardes.hit; +const Key = @import("plain").Key; +const hit = @import("Event.zig").hit; const sel_slot = pardes.sel_slot; const Effect = pardes.Effect; const Pardes = pardes.Pardes; -const Registers = pardes.Registers; -const Editor = pardes.Editor; +const Registers = @import("Registers.zig"); +const Editor = @import("Editor.zig"); /// An edit's failure, memory or a terminal's rows not read, said by its key. pub const Error = error{ OutOfMemory, WriteFailed, UnknownPoint }; @@ -45,7 +45,8 @@ pub fn setYank(e: Editor, text: []const u8) error{OutOfMemory}!void { else => {}, } try e.registers.put(e.gpa, name, text, e.multi_index.*, e.multi_count.*, e.multi_first.*); - if (name == '+' and e.multi_first.*) e.p.emit(.{ .set_clipboard = {} }); + // the library's `+` is a register its caller fills and reads + if (comptime !Editor.lib) if (name == '+' and e.multi_first.*) e.p.emit(.{ .set_clipboard = {} }); } /// Value `i` of register `name` as the command at range `i` reads it, the @@ -526,11 +527,12 @@ pub fn terminalLines(p: *Pardes, pane: *Pane) ![]const []const u8 { pub fn flatSurface(e: Editor, t: *Text) Error![]const u8 { switch (t.what) { - .body => {}, + // the library's text has no pane: its characters are its own + .body => if (comptime Editor.lib) return t.own orelse "", // the tag as it is shown: the keyboard reaches its prefix too .tag => return if (t.pane()) |pane| try tagline.tagText(e.p, e.scratch, pane) else "", .input => return t.own orelse "", - .column, .workspace => return t.own orelse tagline.headerDefault(e.p, t.what), + .column, .workspace => return t.own orelse if (comptime Editor.lib) "" else tagline.headerDefault(e.p, t.what), } const pane = t.pane() orelse return ""; if (pane.file) |f| return f.content; @@ -574,7 +576,7 @@ fn editText(e: Editor, t: *Text, lo: i32, hi: i32, col: i32) Error!?panes.EditTe } if (t.what != .body and t.what != .input and t.own == null) t.own = try e.gpa.dupe(u8, try flatSurface(e, t)); - if (t.what != .body) return .{ .text = t.own orelse &.{}, .row0 = 0 }; + if (t.what != .body or comptime Editor.lib) return .{ .text = t.own orelse &.{}, .row0 = 0 }; const pane = t.pane() orelse return null; if (pane.file) |f| return .{ .text = f.content, .row0 = 0 }; if (pane.addon != null) return null; @@ -692,6 +694,16 @@ fn setEditTextSpan(e: Editor, t: *Text, new: []u8, known_end: ?modal.Cursor, spa t.own = new; return; } + if (comptime Editor.lib) { + // the library's text, its own, where the edit ended found as a + // file's is (below) + const found = span orelse panes.File.spanOf(t.own orelse "", new); + const end = known_end orelse modal.positionAt(new, new.len - found.tail); + t.last_edit = .{ .row = @intCast(end.row), .col = @intCast(end.col) }; + if (t.own) |old| e.gpa.free(old); + t.own = new; + return; + } const pane = t.pane() orelse return retireEditText(e, new); // A live query pane's rows are its line 1's (Query.zig): an edit there // is refused, as a tag's prefix refuses one, and one from line 1 into @@ -733,7 +745,8 @@ fn setEditTextSpan(e: Editor, t: *Text, new: []u8, known_end: ?modal.Cursor, spa /// The file whose text `t` edits in place (File.replace), the bytes it puts /// in and no copy of the text: a file's body, not a live query's (whose /// edits `setEditTextSpan` cuts to its line 1). -fn bodyFile(t: *Text) ?*panes.File.State { +inline fn bodyFile(t: *Text) ?*panes.File.State { + if (comptime Editor.lib) return null; if (t.what != .body) return null; const pane = t.pane() orelse return null; const f = if (pane.file) |*file| file else return null; @@ -1814,7 +1827,7 @@ pub fn normalToggleComment(e: Editor, t: *Text) Error!void { } next = @max(next, end); } - const file = if (t.what != .body) null else if (t.pane()) |pane| pane.file else null; + const file = if (Editor.lib or t.what != .body) null else if (t.pane()) |pane| pane.file else null; const ext = if (file) |f| std.Io.Dir.path.extension(f.path) else ""; var token: []const u8 = config.comment_token_default; lang: for (config.comment_tokens) |row| { @@ -2049,8 +2062,11 @@ pub fn pushUndo(e: Editor, t: *Text) error{OutOfMemory}!void { // one keystroke, one undo step — even when it edited at ten cursors. if (!e.multi_first.*) return; switch (t.what) { - // A B1 chord took its one undo point when it began (mouse.zig). - .body => if (e.p.view().chord_hold) return, + // A B1 chord took its one undo point when it began (mouse.zig); + // the library's text keeps its own undo, as a tag does. + .body => if (comptime Editor.lib) + return t.remember(e.gpa, if (t.own) |own| .{ .text = own } else null) + else if (e.p.view().chord_hold) return, .tag, .column, .workspace => return t.remember(e.gpa, if (t.own) |own| .{ .text = own } else null), // a prompt's answer is typed once and gone; it keeps no history .input => return, @@ -2063,6 +2079,7 @@ pub fn pushUndo(e: Editor, t: *Text) error{OutOfMemory}!void { /// Undo (back) or redo one step of the text's history: its file's, its /// terminal overlay's, or a tag's or header's own. pub fn undoStep(e: Editor, t: *Text, back: bool) error{OutOfMemory}!void { + if (comptime Editor.lib) return stepOwn(e, t, back); if (t.what == .tag or t.what == .column or t.what == .workspace) return stepOwn(e, t, back); if (t.what != .body) return; const pane = t.pane() orelse return; |
