summaryrefslogtreecommitdiff
path: root/src/keys.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/keys.zig')
-rw-r--r--src/keys.zig24
1 files changed, 10 insertions, 14 deletions
diff --git a/src/keys.zig b/src/keys.zig
index 8b67a9d1..05148fed 100644
--- a/src/keys.zig
+++ b/src/keys.zig
@@ -43,9 +43,9 @@ pub fn cycleMode(p: *Pardes, id: usize) void {
pane.body.mode = .normal;
pane.body.normal.clear();
},
- .normal => edit.enterInsert(p, &pane.body, .at, 1) catch |err| p.reportError(id, "edit", err),
+ .normal => edit.enterInsert(p.editor(), &pane.body, .at, 1) catch |err| p.reportError(id, "edit", err),
.insert => {
- edit.exitInsert(p, &pane.body);
+ edit.exitInsert(p.editor(), &pane.body);
if (pane.isTerminal()) enterTty(p, id);
},
}
@@ -232,7 +232,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
pane.focus = .body;
}
for ([_]*Text{ &pane.body, &pane.tag }) |t| {
- if (t.mode == .insert) edit.exitInsert(p, t);
+ if (t.mode == .insert) edit.exitInsert(p.editor(), t);
t.normal.clear();
t.select = false;
}
@@ -342,7 +342,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
p.setMessage(p.view().active, "name drafted: Enter renames the buffer, Esc drops the draft");
return;
}
- edit.handleInsert(p, &pane.input, key);
+ edit.handleInsert(p.editor(), &pane.input, key);
return;
}
if (header == null and pane.prompt != .none) {
@@ -365,7 +365,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
}
return;
}
- edit.handleInsert(p, &pane.input, key);
+ edit.handleInsert(p.editor(), &pane.input, key);
if (normal.selRegexArmed(pane)) |a| if (panes.promptTarget(p, pane)) |answered| normal.applySelRegex(p, pane, answered, a.pat, a.mode);
return;
}
@@ -381,7 +381,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
if (t.what != .body) {
// An explicit selection, else the word under the cursor in the
// text as it is shown: a tag's prefix is part of what a word is.
- const shown = p.scratch.allocator().dupe(u8, edit.flatSurface(p, t) catch |err| return p.reportError(p.view().active, "exec", err)) catch |err| return p.reportError(p.view().active, "exec", err);
+ const shown = p.scratch.allocator().dupe(u8, edit.flatSurface(p.editor(), t) catch |err| return p.reportError(p.view().active, "exec", err)) catch |err| return p.reportError(p.view().active, "exec", err);
const range = t.primaryRange(shown, 0);
const lo = @min(range.anchor, range.head);
const hi = @max(range.anchor, range.head);
@@ -408,7 +408,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
exec.runBuiltin(p, cmd, p.view().active, "", txt);
return;
}
- edit.pinPaneCursor(p, &pane.body);
+ edit.pinPaneCursor(p.editor(), &pane.body);
const explicit = (if (pane.addon) |k| k.selection.len > 0 else false) or
(pane.body.vsel.active and pane.body.vsel.explicit);
if (explicit) {
@@ -442,11 +442,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
};
const was = t.mode;
switch (t.mode) {
- .normal => normal.handleNormal(p, t, key),
- .insert => if (hit(key, config.escape) and !t.reg_wait)
- edit.exitInsert(p, t)
- else
- edit.handleInsert(p, t, key),
+ .normal, .insert => _ = normal.textKey(p.editor(), t, key),
.tty => forwardKey(p, p.view().active, key),
}
// `.`'s log: the keys of the normal command that entered insert
@@ -771,7 +767,7 @@ test "raw tty forwards Ctrl letters and former global shortcuts to the child" {
defer p.deinit();
var buf: [256]u8 = undefined;
_ = test_api.ptyBytes(p, null, &buf);
- try edit.setYank(p, "register text");
+ try edit.setYank(p.editor(), "register text");
for ('a'..'z' + 1) |letter| {
if (letter == p.tty_toggle) continue; // editor/TTY mode shortcut
if (letter == 'v') continue; // the window's paste, asserted just below
@@ -826,7 +822,7 @@ test "s in a header selects in the header's own text" {
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expect(p.view().header != null and pane.prompt == .none);
var ranges: [Text.max_selections]modal.Selection = undefined;
- const text = try edit.flatSurface(p, &p.global_tag);
+ const text = try edit.flatSurface(p.editor(), &p.global_tag);
const got = p.global_tag.ranges(text, 0, &ranges);
try std.testing.expectEqual(@as(usize, 2), got.n); // Newcol, Joincol
try std.testing.expectEqual(@as(u16, 0), pane.body.nsel);