summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/panes.zig62
-rw-r--r--test/pdf.zig27
2 files changed, 84 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 {
diff --git a/test/pdf.zig b/test/pdf.zig
index 7a05447e..beeb0b40 100644
--- a/test/pdf.zig
+++ b/test/pdf.zig
@@ -2055,3 +2055,30 @@ test "Esc back into a PDF keeps the offset within its page" {
// snap, so a test that watched the offset alone would not see it coming.
try std.testing.expect(!pv.scroll_to_page_pending);
}
+
+test "PDF Back and Forward clear selections and land on recorded pages" {
+ if (!pdf_enabled or platform == .web) return error.SkipZigTest;
+ const p = try Pardes.init(std.testing.allocator, .{ .file = "docs/design.pdf", .cols = 80, .rows = 28 });
+ defer p.deinit();
+ p.native_images = true;
+ p.presentation.enabled = false;
+ const pane = p.panes[0].?;
+ const state = &pane.pdf.?;
+ try std.testing.expect(state.page_count > 1);
+ try std.testing.expect(state.focusLocation(p.pdf_gpa, 2, 0));
+ p.njumps = 2;
+ p.jcur = 1;
+ p.jumps[0] = .{ .pane = 0, .serial = pane.serial, .line = 1, .col = 0 };
+ p.jumps[1] = .{ .pane = 0, .serial = pane.serial, .line = 2, .col = 0 };
+ for ([_]u21{ 'o', 'i' }, 0..) |key, destination| {
+ try std.testing.expectEqual(panes.Pdf.SelectionUpdate.changed, state.setSelection(p.pdf_gpa, .{ .x = 0, .y = 0 }, .{ .x = 1, .y = 1 }, true));
+ try std.testing.expect(state.selection != null and state.selection_text.len > 0);
+ p.update(.{ .key = .{ .cp = key, .ctrl = true } });
+ try std.testing.expectEqual(destination, p.jcur);
+ try std.testing.expectEqual(destination, state.page);
+ try std.testing.expect(state.selection == null);
+ try std.testing.expect(state.selection_page == null);
+ try std.testing.expectEqual(@as(usize, 0), state.selection_text.len);
+ try std.testing.expect(state.drag_anchor == null and state.drag_head == null);
+ }
+}