diff options
Diffstat (limited to 'core/Core.zig')
| -rw-r--r-- | core/Core.zig | 112 |
1 files changed, 62 insertions, 50 deletions
diff --git a/core/Core.zig b/core/Core.zig index a22822c2..ccdc8d6f 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -1001,24 +1001,11 @@ fn setLastDumpInner(p: *Pardes, path: []const u8) void { ctlfs.events.notePath(p, "dump", path); } -/// The workspace tag's `Restore <path>` names `path` from now on: the -/// default's does by itself, and one the tag was edited around (its own -/// text) has the old path swapped, never left pointing at a dump that is -/// not the last. +/// The window row's `Restore <path>` names `path` from now on: a computed +/// word (UX K'2, tagline.headerWords), never the user's text. pub fn pointRestoreAt(p: *Pardes, path: []const u8) void { const copy = p.gpa.dupe(u8, path) catch |err| return p.reportError(.at(p.view().active), "Restore", err); - if (p.last_dump) |old| { - if (p.global_tag.own) |own| swap: { - const a = p.scratch.allocator(); - const was = std.fmt.allocPrint(a, "Restore {s}", .{old}) catch break :swap; - if (std.mem.indexOf(u8, own, was) == null) break :swap; - const now = std.fmt.allocPrint(a, "Restore {s}", .{path}) catch break :swap; - const swapped = std.mem.replaceOwned(u8, p.gpa, own, was, now) catch break :swap; - p.gpa.free(own); - p.global_tag.own = swapped; - } - p.gpa.free(old); - } + if (p.last_dump) |old| p.gpa.free(old); p.last_dump = copy; } @@ -1977,7 +1964,9 @@ pub fn sync(p: *Pardes) void { // A file opened or closed this step: the kept list follows. p.saveRecent(); tagline.flattenHeaders(p); - if (p.headerColumn() != null and layout.columnBarHeight(p) == 0) { + // A column's tag with no row to be in lets the keyboard go; a lone + // column's keeps it in the window row (UX K'2). + if (p.headerColumn() != null and layout.columnBarHeight(p) == 0 and !layout.columnInWindowRow(p)) { tagline.exitHeader(p); } pardes.panes.reapPanes(p); @@ -2549,25 +2538,30 @@ test "topbar hover highlights exactly the executable word" { defer frame.deinit(); _ = try p.render(frame.allocator()); - p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = TAG_TEXT_INSET + 1, .row = 0 } }); - _ = frame.reset(.retain_capacity); - const hovered = try p.render(frame.allocator()); - for (0.."Newcol".len) |col| { - const cell = hovered.at(TAG_TEXT_INSET + @as(u16, @intCast(col)), 0); - try std.testing.expectEqual(Color{ .rgb = p.theme().sel_bg }, cell.style.bg); - try std.testing.expectEqual(Color{ .rgb = p.theme().sel_fg }, cell.style.fg); - } - try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, hovered.at(TAG_TEXT_INSET + 6, 0).style.bg); + // Each side of the window row (UX K'2): the lone column's `New`, then + // the window's `Find`. + const words = tagline.windowRow(p).words; + for ([_]struct { at: u16, len: u16 }{ .{ .at = TAG_TEXT_INSET, .len = "New".len }, .{ .at = words, .len = "Find".len } }) |word| { + p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = word.at + 1, .row = 0 } }); + _ = frame.reset(.retain_capacity); + const hovered = try p.render(frame.allocator()); + for (0..word.len) |col| { + const cell = hovered.at(word.at + @as(u16, @intCast(col)), 0); + try std.testing.expectEqual(Color{ .rgb = p.theme().sel_bg }, cell.style.bg); + try std.testing.expectEqual(Color{ .rgb = p.theme().sel_fg }, cell.style.fg); + } + try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, hovered.at(word.at + word.len, 0).style.bg); - p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = TAG_TEXT_INSET + 6, .row = 0 } }); - _ = frame.reset(.retain_capacity); - const whitespace = try p.render(frame.allocator()); - try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, whitespace.at(TAG_TEXT_INSET + 1, 0).style.bg); + p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = word.at + word.len, .row = 0 } }); + _ = frame.reset(.retain_capacity); + const whitespace = try p.render(frame.allocator()); + try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, whitespace.at(word.at + 1, 0).style.bg); + } p.update(.pointer_leave); _ = frame.reset(.retain_capacity); const left = try p.render(frame.allocator()); - try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, left.at(TAG_TEXT_INSET + 1, 0).style.bg); + try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, left.at(words + 1, 0).style.bg); } test "pane-tag Exec prefers Term and argument builtins before shell fallback" { @@ -3757,18 +3751,17 @@ test "tabbed file aligns syntax cursor and mouse at the nearest insertion gap" { try std.testing.expect(look.expandedSel(p, pane, .{ .state = .dragging, .c0 = separator, .c1 = separator, .r0 = BOX_H, .r1 = BOX_H }) == null); } -test "the workspace tag's Restore word names the last dump, the tag edited around it or not, across a Restore too" { +test "the window row's Restore word names the last dump, the user's text after it, across a Restore too (UX K'2)" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 20, .tty_only = true }); defer p.deinit(); p.setLastDump("/tmp/a.zon"); - // The tag edited: its own text holds the Restore word as it was then. - p.global_tag.own = try p.gpa.dupe(u8, try std.fmt.allocPrint(p.scratch.allocator(), "{s} Mine", .{tagline.headerDefault(p, .workspace)})); + p.global_tag.own = try p.gpa.dupe(u8, "Mine"); p.setLastDump("/tmp/b.zon"); - try std.testing.expect(std.mem.indexOf(u8, p.global_tag.own.?, "Restore /tmp/b.zon Mine") != null); + try std.testing.expectEqualStrings("Find Grep Newcol Help Exit Restore /tmp/b.zon Mine", tagline.topbar(p)); try dump.dumpState(p); const restored = try dump.restore(p, p.dump_out.?, "/tmp/c.zon"); defer restored.deinit(); - try std.testing.expect(std.mem.indexOf(u8, restored.global_tag.own.?, "Restore /tmp/c.zon Mine") != null); + try std.testing.expectEqualStrings("Find Grep Newcol Help Exit Restore /tmp/c.zon Mine", tagline.topbar(restored)); try std.testing.expectEqualStrings("/tmp/c.zon", restored.last_dump.?); } @@ -3777,27 +3770,45 @@ test "editable workspace and column tags are typed into and persist" { defer p.deinit(); _ = try p.setTestFile("untouched\n"); p.presented(); - try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.view().rects[0].y); + // One column: its tag in the window row, no column row (UX K'2). + try std.testing.expectEqual(TOPBAR_H, p.view().rects[0].y); + const words = tagline.windowRow(p).words; // a sweep over a header is its selection, the caret where it ended - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = TAG_TEXT_INSET, .row = 0 } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = TAG_TEXT_INSET + 6, .row = 0 } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = TAG_TEXT_INSET + 6, .row = 0 } }); + p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = words, .row = 0 } }); + p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = words + 6, .row = 0 } }); + p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = words + 6, .row = 0 } }); try std.testing.expect(p.global_tag.vsel.active and p.global_tag.vsel.col == 0 and p.global_tag.cur_col == 6); - // A clicked header is in normal mode: `a` types after the sweep's - // last character, the blank it ended on. + // A clicked header is in normal mode: `a` types after the sweep's last + // character, in the computed words: refused, they are no one's. p.update(.{ .key = .{ .cp = 'a', .text = "a" } }); p.update(.{ .key = .{ .cp = 'H', .text = "Help " } }); - try std.testing.expect(std.mem.startsWith(u8, p.global_tag.own.?, "Newcol Help Joincol")); + try std.testing.expect(p.global_tag.own == null); p.update(.{ .key = .{ .cp = Key.escape } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = TAG_TEXT_INSET, .row = TOPBAR_H } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = TAG_TEXT_INSET, .row = TOPBAR_H } }); + // After them, the user's text. + const end: u16 = @intCast(words + "Find Grep Newcol Help Exit ".len); + p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = end, .row = 0 } }); + p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = end, .row = 0 } }); + p.update(.{ .key = .{ .cp = 'i', .text = "i" } }); + p.update(.{ .key = .{ .cp = 'H', .text = "Help " } }); + try std.testing.expectEqualStrings("Help ", p.global_tag.own.?); + try std.testing.expectEqualStrings("Find Grep Newcol Help Exit Help ", tagline.topbar(p)); + p.update(.{ .key = .{ .cp = Key.escape } }); + // The column's tag, at the window row's left: typed into, it has the + // user's text and the column row comes for it; emptied, it goes. + const own: u16 = TAG_TEXT_INSET + "New Term ".len; + p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = own, .row = 0 } }); + p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = own, .row = 0 } }); + try std.testing.expectEqual(@as(?usize, 0), p.headerColumn()); p.update(.{ .key = .{ .cp = 'i', .text = "i" } }); p.update(.{ .key = .{ .cp = 'é', .text = "é" } }); - try std.testing.expect(std.mem.startsWith(u8, tagline.columnTag(p, 0), "éNew")); + try std.testing.expectEqualStrings("New Term é", tagline.columnTag(p, 0)); + try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.view().rects[0].y); p.update(.{ .key = .{ .cp = Key.backspace } }); - try std.testing.expect(std.mem.startsWith(u8, tagline.columnTag(p, 0), "New")); + try std.testing.expectEqualStrings("New Term ", tagline.columnTag(p, 0)); + try std.testing.expectEqual(TOPBAR_H, p.view().rects[0].y); + try std.testing.expectEqual(@as(?usize, 0), p.headerColumn()); p.update(.{ .paste = "Grep " }); - try std.testing.expect(std.mem.startsWith(u8, tagline.columnTag(p, 0), "Grep New")); + try std.testing.expectEqualStrings("New Term Grep ", tagline.columnTag(p, 0)); try std.testing.expectEqualStrings("untouched\n", p.panes[0].?.file.?.content); try dump.dumpState(p); const restored = try dump.restore(p, p.dump_out.?, "test"); @@ -3809,7 +3820,7 @@ test "editable workspace and column tags are typed into and persist" { try dump.dumpState(p); const empty = try dump.restore(p, p.dump_out.?, "test"); defer empty.deinit(); - try std.testing.expectEqualStrings("", tagline.columnTag(empty, 0)); + try std.testing.expectEqualStrings("New Term ", tagline.columnTag(empty, 0)); } test "column tag first-cell execution keeps New local to the clicked column" { @@ -3837,6 +3848,7 @@ test "a screen too short for the column row releases a column tag's focus withou defer p.deinit(); const pane = try p.setTestFile("unchanged body\n"); p.view().col_tags[0].own = try p.gpa.dupe(u8, "New Help"); + p.sync(); p.presented(); const shown = p.view().rects[0]; try std.testing.expectEqual(TOPBAR_H + COLBAR_H, shown.y); @@ -3850,7 +3862,7 @@ test "a screen too short for the column row releases a column tag's focus withou try std.testing.expect(p.view().header == null and p.headerColumn() == null); p.update(.{ .resize = .{ .cols = 60, .rows = 12 } }); try std.testing.expectEqual(shown, p.view().rects[0]); - try std.testing.expectEqualStrings("New Help", tagline.columnTag(p, 0)); + try std.testing.expectEqualStrings("New Term New Help", tagline.columnTag(p, 0)); try std.testing.expectEqualStrings("unchanged body\n", pane.file.?.content); } |
