summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pardes.zig41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index e92f9623..2a74e441 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -3192,6 +3192,33 @@ fn pardes_ctlfs_ctlText(p: *Pardes, pane: *Pane) []const u8 {
return th.rd(p, ctlfs.Node.of(pane.serial, .ctl), 0, 4096).bytes;
}
+test "a name typed into the tag's path survives Esc, pending, and the next Enter renames; a second Esc drops it" {
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true });
+ defer p.deinit();
+ const pane = try p.setTestFile("x\n");
+ for ([_]bool{ true, false }) |enter| {
+ tagline.enterTag(p, pane);
+ pane.tag.mode = .insert;
+ pane.tag.cur_row = 0;
+ pane.tag.cur_col = 1;
+ p.update(.{ .key = .{ .cp = 'z', .text = "z" } });
+ try std.testing.expect(pane.prompt == .name);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expect(pane.prompt == .name);
+ // A stray key changes nothing while it waits.
+ p.update(.{ .key = .{ .cp = 'q', .text = "q" } });
+ if (enter) {
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ try std.testing.expectEqualStrings("/ztest.txt", pane.file.?.path);
+ } else {
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expect(pane.prompt != .name);
+ try std.testing.expectEqualStrings("/ztest.txt", pane.file.?.path);
+ }
+ }
+}
+
test "tabbed file aligns syntax cursor and mouse at the nearest insertion gap" {
const gpa = std.testing.allocator;
const p = try Pardes.init(gpa, .{ .cols = 60, .rows = 12 });
@@ -6355,16 +6382,28 @@ pub const Pardes = struct {
}
if (header == null and pane.prompt == .name) {
// Enter or the execute key commits the draft and the keyboard
- // goes back to the body; Esc drops it.
+ // goes back to the body. Esc while typing keeps the draft,
+ // pending, as Esc keeps any edit: Enter then renames, and a
+ // second Esc drops it. Pending, no other key changes it.
if (hit(key, config.look_key) or hit(key, config.exec_key)) {
if (tagline.commitTagName(p, pane)) pane.focus = .body;
return;
}
+ const pending = pane.input.mode != .insert;
+ if (hit(key, config.escape) and !pending) {
+ pane.input.mode = .normal;
+ if (p.paneIdOf(pane)) |id| p.setMessage(id, "name drafted: Enter renames the buffer, Esc drops the draft");
+ return;
+ }
if (hit(key, config.escape)) {
pane.closePrompt();
pane.focus = .body;
return;
}
+ if (pending) {
+ if (p.paneIdOf(pane)) |id| p.setMessage(id, "name drafted: Enter renames the buffer, Esc drops the draft");
+ return;
+ }
edit.handleInsert(p, &pane.input, key);
return;
}