diff options
Diffstat (limited to 'core/edit.zig')
| -rw-r--r-- | core/edit.zig | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/core/edit.zig b/core/edit.zig index fa442fca..12cd7706 100644 --- a/core/edit.zig +++ b/core/edit.zig @@ -540,7 +540,8 @@ pub fn flatSurface(e: Editor, t: *Text) Error![]const u8 { // 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 if (comptime Editor.lib) "" else tagline.headerDefault(e.p, t.what), + // a header as it is shown: its computed words, then its own text + .column, .workspace => return if (comptime Editor.lib) t.own orelse "" else try tagline.headerText(e.p, t), } const pane = t.pane() orelse return ""; if (pane.file) |f| return f.content; @@ -576,14 +577,13 @@ pub fn paneWrapWidth(e: Editor, t: *Text) usize { /// Route shared edit operations to the characters `t` edits: its own, or /// for a body its file's content or its terminal's overlay. fn editText(e: Editor, t: *Text, lo: i32, hi: i32, col: i32) Error!?panes.EditText { - // A tag or header nobody has changed shows its default; the first edit - // makes that default its own text. + // A tag or a header is edited as it is shown, its computed words and + // all; what an edit leaves after them is its own text (setEditTextSpan). if (t.what == .tag) { const pane = t.pane() orelse return null; return .{ .text = try tagline.tagText(e.p, e.scratch, pane), .row0 = 0 }; } - if (t.what != .body and t.what != .input and t.own == null) - t.own = try e.gpa.dupe(u8, try flatSurface(e, t)); + if (comptime !Editor.lib) if (t.what == .column or t.what == .workspace) return .{ .text = try tagline.headerText(e.p, t), .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 }; @@ -703,6 +703,20 @@ fn setEditTextSpan(e: Editor, t: *Text, new: []u8, known_end: ?modal.Cursor, spa t.own = tail; return; } + if (comptime !Editor.lib) if (t.what == .column or t.what == .workspace) { + // A header's computed words (UX K'2) are no one's to edit, as a + // tag's prefix is not. + defer retireEditText(e, new); + const words = tagline.headerWords(e.p, t.what); + if (!std.mem.startsWith(u8, new, words) or new.len == words.len or new[words.len] != ' ') { + t.refused = true; + return; + } + const tail = try e.gpa.dupe(u8, new[words.len + 1 ..]); + if (t.own) |old| e.gpa.free(old); + t.own = tail; + return; + }; if (t.what != .body) { if (t.own) |old| e.gpa.free(old); t.own = new; |
