summaryrefslogtreecommitdiff
path: root/test/panes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-15 20:17:50 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:14 -0300
commit179863c0a7b011d5a4bd5e064f7d021d239aa96e (patch)
tree02f56d75f3627de575b912d22418e5b4e0eb7d0f /test/panes.zig
parentffa2fd2d4b40bc4ff2a05263cf82ee9638590edd (diff)
downloadpardes-179863c0a7b011d5a4bd5e064f7d021d239aa96e.tar.gz
pardes-179863c0a7b011d5a4bd5e064f7d021d239aa96e.zip
Clear selections when navigating Back and Forward
Diffstat (limited to 'test/panes.zig')
-rw-r--r--test/panes.zig62
1 files changed, 57 insertions, 5 deletions
diff --git a/test/panes.zig b/test/panes.zig
index cb2e8169..81015356 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -899,7 +899,7 @@ const JumpSelectionTests = struct {
if (wrap) try std.testing.expect(std.mem.indexOf(u8, selected, "界") != null);
// Seed two actual locations after the drag, so both history directions
- // must scroll while retaining the rectangle's original source text.
+ // must scroll and discard the previous selection.
p.njumps = 2;
p.jcur = 1;
p.jumps[0] = .{ .pane = 0, .serial = pane.serial, .line = 60, .col = 1 };
@@ -909,25 +909,77 @@ const JumpSelectionTests = struct {
_ = try p.render(frame.allocator());
try std.testing.expectEqual(@as(usize, 0), p.jcur);
try std.testing.expect(pane.file.?.scroll > 20);
- try std.testing.expectEqualStrings(selected, pardes.test_api.heldSelection(p, 0) orelse return error.LostMouseSelection);
+ try LookResetTests.cleared(pane);
+ try std.testing.expect(!pane.vsel.active);
+ try std.testing.expect(pardes.test_api.heldSelection(p, 0) == null);
+ try std.testing.expectEqual(@as(i32, 59), pane.cur_row);
+ try std.testing.expectEqual(@as(i32, 0), pane.cur_col);
+ // A selection created after Back must also disappear on Forward.
+ drag(p, x + 1, y, x + 3, y + 1);
+ try std.testing.expect(pardes.test_api.heldSelection(p, 0) != null);
p.update(.{ .key = .{ .cp = 'i', .ctrl = true } });
_ = frame.reset(.retain_capacity);
_ = try p.render(frame.allocator());
try std.testing.expectEqual(@as(usize, 1), p.jcur);
try std.testing.expectEqual(@as(usize, 0), pane.file.?.scroll);
- try std.testing.expectEqualStrings(selected, pardes.test_api.heldSelection(p, 0) orelse return error.LostMouseSelection);
+ try LookResetTests.cleared(pane);
+ try std.testing.expect(!pane.vsel.active);
+ try std.testing.expect(pardes.test_api.heldSelection(p, 0) == null);
+ try std.testing.expectEqual(@as(i32, 0), pane.cur_row);
+ try std.testing.expectEqual(@as(i32, 0), pane.cur_col);
}
- test "jump selection retains copied rectangle text after scrolling away and back" {
+ test "jump selection clears copied rectangles in both history directions" {
for ([_]bool{ false, true }) |reverse|
try exercise("alpha\nbravo\n", false, reverse, 1, 3, "lph\nrav");
}
- test "jump selection retains wrapped Unicode and tab rectangle text" {
+ test "jump selection clears wrapped Unicode and tab rectangles" {
for ([_]bool{ false, true }) |reverse|
try exercise("界\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\n", true, reverse, 0, 8, null);
}
+
+ test "jump selection clears source and destination state across panes" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 });
+ defer p.deinit();
+ const source = try p.setTestFile("alpha\nbravo\ncharlie\n");
+ const id = p.freeSlot().?;
+ const destination = try p.newDocPane(id);
+ destination.file = .{
+ .path = try p.gpa.dupe(u8, "/jump-destination.txt"),
+ .content = try p.gpa.dupe(u8, "first\nsecond\nthird\n"),
+ .history = try panes.File.History.create(p.gpa),
+ };
+ layout.insert(p, 0, 1, id);
+ layout.compute(p);
+ try LookResetTests.seed(source, "source held text");
+ try LookResetTests.seed(destination, "destination held text");
+ p.active = 0;
+ p.njumps = 2;
+ p.jcur = 1;
+ p.jumps[0] = .{ .pane = @intCast(id), .serial = destination.serial, .line = 3, .col = 2 };
+ p.jumps[1] = .{ .pane = 0, .serial = source.serial, .line = 2, .col = 1 };
+ p.update(.{ .key = .{ .cp = 'o', .ctrl = true } });
+ try std.testing.expectEqual(id, p.active);
+ try std.testing.expectEqual(@as(usize, 0), p.jcur);
+ try LookResetTests.cleared(source);
+ try LookResetTests.cleared(destination);
+ try std.testing.expect(!source.vsel.active and !destination.vsel.active);
+ try std.testing.expectEqual(@as(i32, 2), destination.cur_row);
+ try std.testing.expectEqual(@as(i32, 1), destination.cur_col);
+
+ try LookResetTests.seed(source, "new source held text");
+ try LookResetTests.seed(destination, "new destination held text");
+ p.update(.{ .key = .{ .cp = 'i', .ctrl = true } });
+ try std.testing.expectEqual(@as(usize, 0), p.active);
+ try std.testing.expectEqual(@as(usize, 1), p.jcur);
+ try LookResetTests.cleared(source);
+ try LookResetTests.cleared(destination);
+ try std.testing.expect(!source.vsel.active and !destination.vsel.active);
+ try std.testing.expectEqual(@as(i32, 1), source.cur_row);
+ try std.testing.expectEqual(@as(i32, 0), source.cur_col);
+ }
};
const TagNameTintTests = struct {