summaryrefslogtreecommitdiff
path: root/core/Command.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Command.zig')
-rw-r--r--core/Command.zig58
1 files changed, 48 insertions, 10 deletions
diff --git a/core/Command.zig b/core/Command.zig
index 132ad9e4..bb42bbbd 100644
--- a/core/Command.zig
+++ b/core/Command.zig
@@ -710,6 +710,12 @@ fn tagOf(p: *Pardes) ![]const u8 {
return tagline.tagText(p, p.scratch.allocator(), p.panes[p.view().active].?);
}
+/// The head under the active pane's tag (UX DESIGN M2); none at rest.
+fn headOf(p: *Pardes) ![]const u8 {
+ const h = try TagState.head(p, p.scratch.allocator(), p.panes[p.view().active].?);
+ return if (h) |made| made.text else "";
+}
+
/// Whether `needle` is in `hay`, a run of two spaces or more in either read
/// as two: a right block's padding is its row's (UX D3).
fn has(hay: []const u8, needle: []const u8) bool {
@@ -753,7 +759,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first,
try std.testing.expectEqual(Prompt.Op.command, s.prompt.op);
try std.testing.expectEqual(panes.Pane.Focus.body, pane.focus);
// The head: its key cell, the field, the count, the hints.
- try std.testing.expect(has(try tagOf(p), ": 18 commands Tab complete · ⏎ run · C-r history · esc"));
+ try std.testing.expect(has(try headOf(p), "18 commands C-r history"));
// The rows: the tag's words in its order, `in the tag`, the last ruled
// off; then the commands, each what it takes.
try std.testing.expect(has(try bandRow(p, a, 0), "▶ Save "));
@@ -771,7 +777,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first,
try std.testing.expect(has(first[9].text, "theme") and has(first[9].text, "<theme>"));
// Typing filters both, by the scorer, in their order.
typeKeys(p, "th");
- try std.testing.expect(has(try tagOf(p), ": th = Exec th 1 command "));
+ try std.testing.expect(has(try headOf(p), ": th = Exec th 1 command "));
try std.testing.expect(has(try bandRow(p, a, 0), "▶ theme "));
// Tab: the command, a space after it; the field's plain word is its
// pardes word once it is whole.
@@ -779,7 +785,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first,
try std.testing.expectEqualStrings("theme ", s.field.text());
typeKeys(p, "acme");
const worn = colors.themes[p.theme_preview.?].name;
- try std.testing.expect(has(try tagOf(p), try std.fmt.allocPrint(a, ": theme acme = Exec Theme {s} ", .{worn})));
+ try std.testing.expect(has(try headOf(p), try std.fmt.allocPrint(a, ": theme acme = Exec Theme {s} ", .{worn})));
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expectEqual(TagState.Kind.rest, s.kind);
try std.testing.expectEqualStrings(worn, p.theme().name);
@@ -789,7 +795,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first,
// `:sort`: the selections piped through sort, as `|sort` does.
while (p.nextEffect()) |_| {}
typeKeys(p, "%:sort");
- try std.testing.expect(has(try tagOf(p), ": sort = Exec Edit |sort 1 command"));
+ try std.testing.expect(has(try headOf(p), ": sort = Exec Edit |sort 1 command"));
p.update(.{ .key = .{ .cp = Key.enter } });
var asked: ?u32 = null;
while (p.nextEffect()) |effect| if (effect == .pipe) {
@@ -798,7 +804,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first,
try std.testing.expectEqualStrings("sort", p.pipe.pipeRequest(asked orelse return error.MissingPipeEffect).?.command);
// `:goto 2`: Look `:2`.
typeKeys(p, ":goto 2");
- try std.testing.expect(has(try tagOf(p), ": goto 2 = Look :2 <line> "));
+ try std.testing.expect(has(try headOf(p), ": goto 2 = Look :2 <line> "));
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
// S-Tab: the last row; Tab after it, round to the first. A tag word
@@ -846,7 +852,7 @@ test ":theme lists the themes and the whole window wears the current one, none d
typeKeys(p, ":theme ");
try std.testing.expectEqual(Rows.themes, s.prompt.command.rows);
try std.testing.expectEqual(@as(u16, @intCast(colors.themes.len)), s.nhits);
- try std.testing.expect(has(try tagOf(p), try std.fmt.allocPrint(a, " {d} themes · the window wears the current one ", .{colors.themes.len})));
+ try std.testing.expect(has(try headOf(p), try std.fmt.allocPrint(a, " {d} themes · the window wears the current one ", .{colors.themes.len})));
// The window wears the first: its colours, its chrome; no pane dimmed.
try std.testing.expectEqualStrings(colors.themes[s.hits[0]].name, p.theme().name);
try std.testing.expectEqual(colors.Chrome.of(p.theme()), p.chrome().*);
@@ -890,9 +896,9 @@ test ":theme lists the themes and the whole window wears the current one, none d
try std.testing.expectEqual(Rows.values, s.prompt.command.rows);
try std.testing.expectEqual(@as(u16, 2), s.nhits);
try std.testing.expect(has(try bandRow(p, a, 0), "▶ on now"));
- try std.testing.expect(has(try tagOf(p), ": set Wrap = Exec Wrap 2 values "));
+ try std.testing.expect(has(try headOf(p), ": set Wrap = Exec Wrap 2 values "));
typeKeys(p, "of");
- try std.testing.expect(has(try tagOf(p), ": set Wrap of = Exec Wrap of 1 value "));
+ try std.testing.expect(has(try headOf(p), ": set Wrap of = Exec Wrap of 1 value "));
p.update(.{ .key = .{ .cp = Key.tab } });
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expect(!p.settings.wrap);
@@ -914,7 +920,7 @@ test ":theme lists the themes and the whole window wears the current one, none d
// :open: the line goes to Find, the rest of it the query, the keys
// after it typed into Find's field.
typeKeys(p, ":o");
- try std.testing.expect(has(try tagOf(p), ": o = Exec Find "));
+ try std.testing.expect(has(try headOf(p), ": o = Exec Find "));
typeKeys(p, " te");
try std.testing.expectEqual(TagState.Kind.pick, s.kind);
try std.testing.expectEqual(pardes.Pick.Source.find, pardes.Pick.live(p).?.source);
@@ -956,7 +962,7 @@ test ": has a history of its own: Up and Down bring back the lines Enter ran, ne
typeKeys(p, ":");
p.update(.{ .key = .{ .cp = Key.up } });
try std.testing.expectEqualStrings("goto 2", s.field.text());
- try std.testing.expect(has(try tagOf(p), ": goto 2 = Look :2 <line> "));
+ try std.testing.expect(has(try headOf(p), ": goto 2 = Look :2 <line> "));
p.update(.{ .key = .{ .cp = Key.up } });
try std.testing.expectEqualStrings("set Wrap off", s.field.text());
try std.testing.expectEqual(Rows.values, s.prompt.command.rows);
@@ -1087,3 +1093,35 @@ test ": lists the words of the pane's kind its tag does not show now, `for this
try std.testing.expectEqual(@as(usize, 1), p.view().ncol);
try std.testing.expectEqualStrings("one\n", pane.file.?.content);
}
+
+test ": hangs its field under the tag, which stays as at rest; `:` on the empty field gives the keyboard to that tag's own text right above it, the head's row the body's again (UX DESIGN M3)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 });
+ defer p.deinit();
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const pane = try p.setTestFile("one\ntwo\n");
+ pane.tag.own = try p.gpa.dupe(u8, "notes");
+ p.sync();
+ const id = p.view().active;
+ const r = p.view().rects[id];
+ const head_y = p.tagTop(pane, r) + pane.tag_rows;
+ const rest = try a.dupe(u8, try tagOf(p));
+ const at_rest = try a.dupe(pardes.Cell, (try p.render(a)).cells);
+ const cols = p.surface.cols;
+ typeKeys(p, ":");
+ try std.testing.expectEqual(TagState.Kind.prompt, p.view().tag_state.kind);
+ try std.testing.expectEqualStrings(rest, try tagOf(p));
+ var s = try p.render(a);
+ try std.testing.expectEqualStrings(":", s.at(r.x + pardes.TAG_TEXT_INSET, head_y).grapheme());
+ typeKeys(p, ":");
+ try std.testing.expectEqual(TagState.Kind.rest, p.view().tag_state.kind);
+ try std.testing.expectEqual(panes.Pane.Focus.tag, pane.focus);
+ try std.testing.expectEqualStrings(rest, try tagOf(p));
+ s = try p.render(a);
+ for (r.x..r.x + r.w) |x| try std.testing.expectEqualStrings(at_rest[@as(usize, head_y) * cols + x].grapheme(), s.cells[@as(usize, head_y) * cols + x].grapheme());
+ // The caret at the start of the tag's own text.
+ const own: u16 = @intCast(panes.File.displayWidth(p.settings.tab, rest[0..std.mem.indexOf(u8, rest, "notes").?]));
+ try std.testing.expectEqual(r.x + pardes.TAG_TEXT_INSET + own, s.cursor.?.x);
+ try std.testing.expectEqual(p.tagTop(pane, r), s.cursor.?.y);
+}