summaryrefslogtreecommitdiff
path: root/core/Messages.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Messages.zig')
-rw-r--r--core/Messages.zig38
1 files changed, 36 insertions, 2 deletions
diff --git a/core/Messages.zig b/core/Messages.zig
index 6231e3d1..2cb196f6 100644
--- a/core/Messages.zig
+++ b/core/Messages.zig
@@ -732,6 +732,10 @@ pub fn noticeRow(p: *const Pardes, width: usize, out: *[notice_row_cap]u8) Row {
r.writeAll("SPC e walk") catch {}
else if (m.len > 0)
r.print("{d} message{s} \u{b7} SPC h m", .{ m.len, if (m.len == 1) "" else "s" }) catch {};
+ // The keys of a root whose level waits for its delay, at once (UX D12:
+ // vim's showcmd; the tag stays at rest until the level shows).
+ var keys: [64]u8 = undefined;
+ if (pardes.TagState.pending(p, p.view(), &keys)) |typed| r.print("{s}{s}", .{ if (r.end > 0) " " else "", typed }) catch {};
const tail = r.buffered();
// The left cut to make room for the right, a blank between them.
const tail_w = panes.File.displayWidth(tab, tail);
@@ -1332,6 +1336,34 @@ test "a burst of the same message is one message, counted, and moves nothing on
try std.testing.expect(std.mem.endsWith(u8, row.text[0..row.left], "3 files \u{d7}10"));
}
+test "a question never adds a row to its tag: at every width the asking tag takes the rows the tag takes at rest, its answers always shown, the question cut before them" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 30 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\n");
+ const id = p.view().active;
+ // A short name: the tag's rows have room for it and the answers.
+ p.gpa.free(pane.file.?.path);
+ pane.file.?.path = try p.gpa.dupe(u8, "/t/c.zig");
+ const f = &pane.file.?;
+ f.saved_hash = panes.File.fileHash(f);
+ for ([_]u21{ 'G', 'o', 'f', Key.escape }) |cp| p.update(.{ .key = .{ .cp = cp } });
+ // The tag's own words cut to one, so the question is the longer.
+ pane.tag.own = try p.gpa.dupe(u8, " Put");
+ p.update(.{ .file_changed = .{ .pane = .at(id), .bytes = "zero\n" } });
+ _ = p.messages.waiting(pane) orelse return error.NotAsked;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ for (56..161) |cols| {
+ p.update(.{ .resize = .{ .cols = @intCast(cols), .rows = 30 } });
+ p.sync();
+ const rest = pardes.layout.wantedTagRows(p, id);
+ try std.testing.expect(pane.tag_rows <= @max(rest, 1));
+ const shown = try pardes.tagline.tagText(p, frame.allocator(), pane);
+ for ([_][]const u8{ "r Reload", "k Keep mine", "d Diff" }) |word| try std.testing.expect(std.mem.indexOf(u8, shown, word) != null);
+ _ = frame.reset(.retain_capacity);
+ }
+}
+
test "a file changed on disk under unsaved text asks in its tag and never takes the keyboard: SPC e's keyboard answers, d shows the disk's lines as ghosts, Esc leaves it waiting, B2 on Reload reads it again" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20 });
defer p.deinit();
@@ -1368,9 +1400,11 @@ test "a file changed on disk under unsaved text asks in its tag and never takes
try std.testing.expect(std.mem.indexOf(u8, prefix, "changed on disk") == null);
// The tag's own text is no one's to edit meanwhile.
try std.testing.expect((try pardes.TagState.head(p, frame.allocator(), pane)) != null);
- // Out of rest (SPC: its key cell at once) the level's head, not the
- // question; at rest again, the question.
+ // Out of rest (SPC's level shown) the level's head, not the question;
+ // at rest again, the question.
p.update(.{ .key = .{ .cp = ' ' } });
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, frame.allocator(), pane), "changed on disk") == null);
p.update(.{ .key = .{ .cp = Key.escape } });
try std.testing.expect(std.mem.indexOf(u8, try pardes.tagline.tagText(p, frame.allocator(), pane), "changed on disk") != null);