summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-08 21:58:00 -0300
committerGabriel Schneider <[email protected]>2026-11-08 22:02:41 -0300
commite303492ced70ac4bab5d09b53eda633cbf9108df (patch)
tree9979c890b3e2f30467e72933e7ff569d6f069487
parent8597144cffab56c35d5c6642899116828d0211e6 (diff)
downloadpardes-e303492ced70ac4bab5d09b53eda633cbf9108df.tar.gz
pardes-e303492ced70ac4bab5d09b53eda633cbf9108df.zip
helix: zz and zc put the cursor's line (rows - 1) / 2 rows down the view, helix's align_view (helix-view/src/lib.rs:62-67), where pardes put it rows / 2 - 1 down, a row too high on an odd view: hxdiff's four gt-after-zz cases at 80x24 (21 body rows) pass, gb-after-zz passed only by the view's own missing row and now waits for it; a behaviour test centres l15 on the 21-row view
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--src/normal.zig4
-rw-r--r--test/behaviour/keys.zig16
2 files changed, 19 insertions, 1 deletions
diff --git a/src/normal.zig b/src/normal.zig
index 4d3cc96b..6d7eb69c 100644
--- a/src/normal.zig
+++ b/src/normal.zig
@@ -664,10 +664,12 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) edit.Error!
const at = t.last_edit orelse return;
return t.pointMove(text, range, modal.offsetAt(text, .{ .row = @intCast(@max(0, at.row)), .col = @intCast(@max(0, at.col)) }));
},
+ // helix align_view: the cursor's row goes `above` rows down the
+ // view, the middle of an odd one and the upper middle of an even one
.view_top, .view_center, .view_bottom => if (t.what == .body) {
const above: i32 = switch (a.role) {
.view_top => 0,
- .view_center => @divTrunc(@as(i32, pane.rows), 2) - 1,
+ .view_center => @divTrunc(@as(i32, pane.rows) - 1, 2),
else => @as(i32, pane.rows) - 1,
};
pane.scrollBy(t.cur_row - (pane.scroll() + above));
diff --git a/test/behaviour/keys.zig b/test/behaviour/keys.zig
index 118681cd..e1f550e3 100644
--- a/test/behaviour/keys.zig
+++ b/test/behaviour/keys.zig
@@ -387,3 +387,19 @@ test "keys: a PDF in normal mode keeps : (its tag and back), SPC (a leader, canc
try std.testing.expect(try s.cursor() == null);
try std.testing.expectEqual(n, try s.focused());
}
+
+test "keys: zz and zc put the cursor's line in the middle row of an odd view, as many lines above it as below (helix align_view)" {
+ var lines: [30][4]u8 = undefined;
+ for (&lines, 0..) |*l, i| _ = try std.fmt.bufPrint(l, "l{d:0>2}\n", .{i});
+ var s = try Session.initFile(std.testing.allocator, std.mem.asBytes(&lines));
+ defer s.deinit();
+ for ([_][]const u8{ "15jzz", "ztzc" }) |keys| {
+ try s.keys(keys);
+ // 80x24 gives the pane 21 rows: l05 to l25, l15 the eleventh
+ const top = (try s.where("l05"))[1];
+ try std.testing.expectEqual(top + 10, (try s.where("l15"))[1]);
+ try std.testing.expectEqual(top + 20, (try s.where("l25"))[1]);
+ try std.testing.expectError(error.NotOnScreen, s.where("l04"));
+ try std.testing.expectError(error.NotOnScreen, s.where("l26"));
+ }
+}