summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Messages.zig28
-rw-r--r--core/TagState.zig19
2 files changed, 45 insertions, 2 deletions
diff --git a/core/Messages.zig b/core/Messages.zig
index dd5c232a..6d8d570d 100644
--- a/core/Messages.zig
+++ b/core/Messages.zig
@@ -1330,6 +1330,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();
diff --git a/core/TagState.zig b/core/TagState.zig
index c364451a..3fceb7f0 100644
--- a/core/TagState.zig
+++ b/core/TagState.zig
@@ -296,8 +296,23 @@ fn asking(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
const i = p.messages.waiting(pane) orelse return null;
const said = &p.messages.live[i];
var b: Builder = .{ .arena = arena };
+ // In the rows the tag takes at rest (UX D13: a question never adds a
+ // row): the hint goes first, then the question is cut, 12 cells at
+ // least, with `…` (the whole of it is on the notice row); its answers
+ // always show.
+ const tab = p.settings.tab;
+ const id = panes.paneIdOf(p, pane) orelse return null;
+ const room = @as(usize, @import("layout.zig").wantedTagRows(p, id)) * tagline.tagWidth(p, id) -| panes.File.displayWidth(tab, try tagline.restPrefix(p, arena, pane));
+ const hint = if (p.view().answering == pane.serial) "· Esc later" else "· SPC e to answer";
+ var answers: usize = 2; // ` ▸`, then each ` k word `
+ for (said.asks.answers()) |a| answers += 3 + panes.File.displayWidth(tab, a.word) + 1;
+ const question = said.words();
+ const wanted = 1 + panes.File.displayWidth(tab, question) + answers;
try b.put(" ");
- try b.put(said.words());
+ if (wanted <= room) try b.put(question) else {
+ try b.put(question[0..panes.File.byteAtDisplay(tab, question, @max(12, room -| (1 + answers)) - 1)]);
+ try b.put("…");
+ }
try b.put(" ");
try b.styled("▸", .key);
for (said.asks.answers()) |a| {
@@ -307,7 +322,7 @@ fn asking(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
try b.put(a.word);
try b.put(" ");
}
- try b.styled(if (p.view().answering == pane.serial) "· Esc later" else "· SPC e to answer", .dim);
+ if (wanted + panes.File.displayWidth(tab, hint) <= room) try b.styled(hint, .dim);
return b.done();
}