summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pardes.zig155
1 files changed, 9 insertions, 146 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index ba09b3b6..2b4fef70 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -8517,56 +8517,6 @@ test "a Rename the language server finds nothing for says so, and changes nothin
try std.testing.expectEqualStrings("const value=1;\n", pane.file.?.content);
}
-test "hopping between two panes does not grow the jump stack" {
- if (platform == .web) return;
- const gpa = std.testing.allocator;
- const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" });
- p.settings.placement = .pardes; // two panes of room, not acme's fit to the doc's two lines
- defer p.deinit();
- p.update(.{ .resize = .{ .cols = 80, .rows = 24 } });
- p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell under the doc
- const doc = 0;
- const shell = p.active;
- try std.testing.expect(shell != doc);
- const depth = p.njumps;
-
- // Esc is Last — the everyday two-pane hop. Each press used to
- // append, so sixty-four of them left the stack remembering nothing else.
- for (0..8) |_| {
- const was = p.active;
- p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expect(p.active != was);
- }
- try std.testing.expectEqual(depth, p.njumps);
-
- // ...and so are the other two ways to switch panes.
- for (0..8) |_| {
- const want = if (p.active == doc) shell else doc;
- const dir: u21 = if (p.active == doc) 'j' else 'k';
- p.update(.{ .key = .{ .cp = ' ' } });
- p.update(.{ .key = .{ .cp = 'w' } });
- p.update(.{ .key = .{ .cp = dir } });
- p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expectEqual(want, p.active);
- }
- try std.testing.expectEqual(depth, p.njumps);
-
- for (0..8) |_| {
- const other = if (p.active == doc) shell else doc;
- const r = p.rects[other];
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = r.x + config.GUTTER + 1, .row = r.y + BOX_H + 1 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = r.x + config.GUTTER + 1, .row = r.y + BOX_H + 1 } });
- try std.testing.expectEqual(other, p.active);
- }
- try std.testing.expectEqual(depth, p.njumps);
-
- const before = p.active;
- exec.runBuiltin(p, .Back, p.active, "", null);
- p.sync();
- try std.testing.expect(p.active != before);
- try std.testing.expectEqual(depth, p.njumps);
-}
-
/// Every `.write` a keystroke produced, joined — what the pane's program would
/// actually have read off its pty.
fn drainWrites(p: *Pardes, buf: []u8) []const u8 {
@@ -8930,35 +8880,15 @@ test "board heap: every allocation failure during boot is a clean OutOfMemory" {
);
}
-test "jump history clears selections and lands at the recorded cursor" {
+test "jump history skips an entry whose pane slot or serial is gone, leaving the selection" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 });
defer p.deinit();
const pane = try p.setTestFile("alpha beta\ngamma delta\nepsilon zeta\n");
p.njumps = 2;
p.jcur = 1;
- p.jumps[0] = .{ .pane = 0, .serial = pane.serial, .line = 3, .col = 8 };
p.jumps[1] = .{ .pane = 0, .serial = pane.serial, .line = 1, .col = 1 };
- for ([_]u21{ 'o', 'i' }, 0..) |key, index| {
- pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true);
- pane.sel[0] = .{ .state = .done, .c0 = 2, .c1 = 5, .r0 = 1, .r1 = 1 };
- try edit.capturePointerSelection(p, pane, 0);
- pane.body.select = true;
- p.update(.{ .key = .{ .cp = key, .ctrl = true } });
- try std.testing.expectEqual(index, p.jcur);
- try std.testing.expectEqual(@as(usize, 2), p.njumps);
- try std.testing.expectEqual(@as(u32, 3), p.jumps[0].line);
- try std.testing.expect(!pane.body.vsel.active and !pane.body.msel.active and !pane.body.select);
- try std.testing.expectEqual(@as(u16, 0), pane.body.nsel);
- try std.testing.expectEqual(.none, pane.sel[0].state);
- try std.testing.expect(pane.pointer_selections[0] == null);
- try std.testing.expectEqual(@as(i32, if (index == 0) 2 else 0), pane.body.cur_row);
- try std.testing.expectEqual(@as(i32, if (index == 0) 7 else 0), pane.body.cur_col);
- }
pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true);
const selected = pane.body.primaryRange(pane.file.?.content, 0);
- p.jumpBy(1); // No forward entry: selection stays untouched.
- try std.testing.expectEqualDeep(selected, pane.body.primaryRange(pane.file.?.content, 0));
- try std.testing.expect(std.mem.indexOf(u8, p.panes[p.active].?.msg[0..p.panes[p.active].?.msg_len], "nothing further on") != null);
for ([_]Loc{
.{ .pane = 15, .serial = pane.serial, .line = 1, .col = 1 },
.{ .pane = 0, .serial = pane.serial + 1, .line = 1, .col = 1 },
@@ -8970,7 +8900,7 @@ test "jump history clears selections and lands at the recorded cursor" {
}
}
-/// A session for the JumpScope tests: four panes of 100 lines in one
+/// A session for the side-button jump test: four panes of 100 lines in one
/// column, A (pane 0) and B each on a file of its own, C on A's file, and O
/// an output buffer, no file behind it. `order` is the jumplist, a letter a
/// place, each letter's n-th place its line 10 + 40n: "ABABA" is A10 B10 A50
@@ -8980,7 +8910,7 @@ const JumpsTest = struct {
ids: [4]usize = .{ 0, 0, 0, 0 },
const letters = "ABCO";
- const Way = enum { call, key, builtin, mouse };
+ const Way = enum { call, mouse };
fn init(order: []const u8) !JumpsTest {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 80 });
@@ -9021,14 +8951,12 @@ const JumpsTest = struct {
return t;
}
- /// One step `delta` through `way`: the function, Ctrl-o or Ctrl-i, the
- /// mouse's side button pressed and let go, or the builtin's word.
+ /// One step `delta` through `way`: the function, or the mouse's side
+ /// button pressed and let go.
fn step(t: JumpsTest, way: Way, delta: i32) void {
const back = delta < 0;
switch (way) {
.call => t.p.jumpBy(delta),
- .key => t.p.update(.{ .key = .{ .cp = if (back) 'o' else 'i', .ctrl = true } }),
- .builtin => _ = t.p.executeBuiltinLine(t.p.active, if (back) "Back" else "Forward"),
.mouse => for ([_]Mouse.Kind{ .press, .release }) |kind|
t.p.update(.{ .mouse = .{ .button = if (back) .back else .forward, .kind = kind, .col = 0, .row = 0 } }),
}
@@ -9054,75 +8982,10 @@ const JumpsTest = struct {
}
};
-test "JumpScope file: Back keeps to the focused file, A50 then A10, and leaves it only once it runs out that way" {
- const t = try JumpsTest.init("BABABA");
- defer t.p.deinit();
- try std.testing.expectEqual(config.Runtime.JumpScope.file, t.p.settings.jump_scope);
- var buf: [128]u8 = undefined;
- // B90, B50 passed over, kept in their places: A has nothing older than
- // A10, so the step after it is the nearest place of any file, B10.
- try std.testing.expectEqualStrings("A50 A10 B10", try t.walk(.call, -1, &buf));
- try std.testing.expectEqual(@as(usize, 6), t.p.njumps);
- // Forward is the mirror, from B10 in B: B's own places first, then A90,
- // the newest, where the Backs started.
- try std.testing.expectEqualStrings("B50 B90 A90", try t.walk(.call, 1, &buf));
- try std.testing.expectEqual(@as(usize, 5), t.p.jcur);
-}
-
-test "JumpScope file: Forward retraces a run of Backs inside one file step for step, back to where it began" {
- const t = try JumpsTest.init("ABABA");
- defer t.p.deinit();
- var buf: [128]u8 = undefined;
- // A1 B1 A2 B2 A3 from A3: nothing older than A1 at all, so Back ends there.
- try std.testing.expectEqualStrings("A50 A10", try t.walk(.call, -1, &buf));
- try std.testing.expectEqual(@as(usize, 0), t.p.jcur);
- try std.testing.expectEqualStrings("A50 A90", try t.walk(.call, 1, &buf));
- try std.testing.expectEqual(@as(usize, 4), t.p.jcur);
- // One Back, one Forward: the same entry, whichever were passed over.
- t.step(.call, -1);
- try std.testing.expectEqual(@as(usize, 2), t.p.jcur);
- t.step(.call, 1);
- try std.testing.expectEqual(@as(usize, 4), t.p.jcur);
- try std.testing.expectEqual(@as(usize, 5), t.p.njumps);
-}
-
-test "JumpScope all: Back and Forward take every place in the order it was jumped to" {
- const t = try JumpsTest.init("ABABA");
- defer t.p.deinit();
- try std.testing.expect(t.p.executeBuiltinLine(t.p.active, "JumpScope all"));
- try std.testing.expectEqual(config.Runtime.JumpScope.all, t.p.settings.jump_scope);
- var buf: [128]u8 = undefined;
- try std.testing.expectEqualStrings("B50 A50 B10 A10", try t.walk(.call, -1, &buf));
- try std.testing.expectEqualStrings("B10 A50 B50 A90", try t.walk(.call, 1, &buf));
- // Bare, the word steps back to file.
- try std.testing.expect(t.p.executeBuiltinLine(t.p.active, "JumpScope"));
- try std.testing.expectEqual(config.Runtime.JumpScope.file, t.p.settings.jump_scope);
-}
-
-test "JumpScope file: from a pane with no file, Back and Forward are global" {
- const t = try JumpsTest.init("OAOBO");
- defer t.p.deinit();
- var buf: [128]u8 = undefined;
- // O90 keeps to nothing: B10, the next older of all. From B, nothing of
- // B is older, so O50; from O, A10; from A, O10.
- try std.testing.expectEqualStrings("B10 O50 A10 O10", try t.walk(.call, -1, &buf));
- try std.testing.expectEqualStrings("A10 O50 B10 O90", try t.walk(.call, 1, &buf));
-}
-
-test "JumpScope file: a file in two panes keeps to the pane first, then the file in the other pane" {
- // C is A's file in a second pane: C10 B10 A10 C50 A50.
- const t = try JumpsTest.init("CBACA");
- defer t.p.deinit();
- var buf: [128]u8 = undefined;
- // From A50: A10 in this pane, over the nearer C50; then none of A's
- // own is older, so the file's in C, C10, over B10.
- try std.testing.expectEqualStrings("A10 C10", try t.walk(.call, -1, &buf));
- // From C10 in C: C50, its own, then the file's newest, A50.
- try std.testing.expectEqualStrings("C50 A50", try t.walk(.call, 1, &buf));
-}
-
-test "Back and Forward take the same steps from Ctrl-o and Ctrl-i, the mouse's side buttons, the builtins and jumpBy" {
- for ([_]JumpsTest.Way{ .call, .key, .builtin, .mouse }) |way| {
+// The keys and builtins are test/behaviour/modes.zig's; a mouse's side
+// buttons have no /mousein bits.
+test "Back and Forward take the same steps from the mouse's side buttons and jumpBy" {
+ for ([_]JumpsTest.Way{ .call, .mouse }) |way| {
const t = try JumpsTest.init("BABABA");
defer t.p.deinit();
var buf: [128]u8 = undefined;