summaryrefslogtreecommitdiff
path: root/src/edit.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/edit.zig')
-rw-r--r--src/edit.zig45
1 files changed, 28 insertions, 17 deletions
diff --git a/src/edit.zig b/src/edit.zig
index 02e138e8..1822db31 100644
--- a/src/edit.zig
+++ b/src/edit.zig
@@ -72,10 +72,9 @@ pub fn typeToTty(p: *Pardes, id: usize, pane: *const Pane, text: []const u8) voi
}
pub fn applyPaste(p: *Pardes, bytes: []const u8) void {
- if (p.topbar_col != null) {
+ if (p.focusedHeader()) |t| {
p.clip_pending = null;
- p.headerReplace(bytes);
- return;
+ return pasteInto(p, t, bytes);
}
const req = p.clip_pending;
p.clip_pending = null;
@@ -96,15 +95,23 @@ pub fn applyPaste(p: *Pardes, bytes: []const u8) void {
if (normal.selRegexArmed(pane)) |a| normal.applySelRegex(p, pane, a.pat, a.split);
return;
}
- const t = if (pane.focus == .tag) &pane.tag else &pane.body;
- if (t.what == .body and pane.isTerminal() and pane.body.mode == .tty) return typeToTty(p, id, pane, bytes);
+ if (pane.focus == .tag) return pasteInto(p, &pane.tag, bytes);
+ if (pane.isTerminal() and pane.body.mode == .tty) return typeToTty(p, id, pane, bytes);
switch (if (req) |r| r.mode else .after) {
- .after => pasteText(p, t, bytes, false, 1),
- .before => pasteText(p, t, bytes, true, 1),
- .replace => replaceWithText(p, t, bytes),
+ .after => pasteText(p, &pane.body, bytes, false, 1),
+ .before => pasteText(p, &pane.body, bytes, true, 1),
+ .replace => replaceWithText(p, &pane.body, bytes),
}
}
+/// A paste into a tag or a header: typed at the caret while it is typed
+/// into, after the cursor's cell in normal mode, as a body's paste is.
+fn pasteInto(p: *Pardes, t: *Text, bytes: []const u8) void {
+ if (bytes.len == 0) return;
+ if (t.mode == .insert) return insertKey(p, t, .{ .cp = bytes[0], .text = bytes });
+ pasteText(p, t, bytes, false, 1);
+}
+
pub fn clipYank(p: *Pardes, pane: *Pane, main_only: bool) void {
if (comptime pdf_enabled) if (pane.pdf) |pv| {
if (pv.selection_text.len > 0) setClipboard(p, pv.selection_text);
@@ -340,8 +347,12 @@ pub fn pinPaneCursor(p: *Pardes, t: *Text) void {
}
pub fn flatSurface(p: *Pardes, t: *Text) ![]const u8 {
- if (t.what == .tag) return Pardes.curTail(t.pane());
- if (t.what != .body) return t.own orelse "";
+ switch (t.what) {
+ .body => {},
+ .tag => return Pardes.curTail(t.pane()),
+ .input => return t.own orelse "",
+ .column, .workspace => return t.own orelse p.headerDefault(t.what),
+ }
const pane = t.pane();
if (pane.file) |f| return f.content;
if (pane.hasPdf()) {
@@ -362,10 +373,10 @@ pub fn paneWrapWidth(p: *const Pardes, 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(p: *Pardes, t: *Text, lo: i32, hi: i32, col: i32) ?panes.EditText {
- // A tag nobody has changed shows its default; the first edit makes that
- // default its own text.
- if (t.what == .tag and t.own == null)
- t.own = p.gpa.dupe(u8, Pardes.defaultTail(t.pane())) catch return null;
+ // A tag or header nobody has changed shows its default; the first edit
+ // makes that default its own text.
+ if (t.what != .body and t.what != .input and t.own == null)
+ t.own = p.gpa.dupe(u8, flatSurface(p, t) catch return null) catch return null;
if (t.what != .body) return .{ .text = t.own orelse &.{}, .row0 = 0 };
const pane = t.pane();
if (pane.file) |f| return .{ .text = f.content, .row0 = 0 };
@@ -1545,7 +1556,7 @@ pub fn pushUndo(p: *Pardes, t: *Text) void {
if (p.multi_on and !p.multi_first) return;
switch (t.what) {
.body => {},
- .tag => return t.remember(p.gpa, if (t.own) |own| .{ .text = own } else null),
+ .tag, .column, .workspace => return t.remember(p.gpa, if (t.own) |own| .{ .text = own } else null),
// a prompt's answer is typed once and gone; it keeps no history
.input => return,
}
@@ -1555,7 +1566,7 @@ pub fn pushUndo(p: *Pardes, t: *Text) void {
}
pub fn doUndo(p: *Pardes, t: *Text) void {
- if (t.what == .tag) return stepOwn(p, t, true);
+ if (t.what == .tag or t.what == .column or t.what == .workspace) return stepOwn(p, t, true);
if (t.what != .body) return;
const pane = t.pane();
if (pane.file != null) return panes.File.undo(p, pane);
@@ -1563,7 +1574,7 @@ pub fn doUndo(p: *Pardes, t: *Text) void {
}
pub fn doRedo(p: *Pardes, t: *Text) void {
- if (t.what == .tag) return stepOwn(p, t, false);
+ if (t.what == .tag or t.what == .column or t.what == .workspace) return stepOwn(p, t, false);
if (t.what != .body) return;
const pane = t.pane();
if (pane.file != null) return panes.File.redo(p, pane);