summaryrefslogtreecommitdiff
path: root/src/mouse.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 00:01:56 -0300
committerGabriel Schneider <[email protected]>2026-11-05 01:00:59 -0300
commit561c240aa2170c61e9744ccb83b05c494fed0de9 (patch)
treef9a0ff8e82df692cf0076b88b26fad535d1125a9 /src/mouse.zig
parent7e4e9f23978ba6c1313415c12064c9267ebbe7f2 (diff)
downloadpardes-561c240aa2170c61e9744ccb83b05c494fed0de9.tar.gz
pardes-561c240aa2170c61e9744ccb83b05c494fed0de9.zip
mouse.chromeTarget: its two passes, on the cell and a cell away, are one loop over the distance, and a seam is seamRowOf, where it was spelled out twice; a test of what a press near chrome takes, which nothing pinned (web.zig's one caller), written and passing on the old code first
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/mouse.zig')
-rw-r--r--src/mouse.zig77
1 files changed, 42 insertions, 35 deletions
diff --git a/src/mouse.zig b/src/mouse.zig
index 426b7d8e..69d1456e 100644
--- a/src/mouse.zig
+++ b/src/mouse.zig
@@ -231,49 +231,56 @@ fn nudgeRightSeam(p: *Pardes, delta: i32) u16 {
pub const ChromeTarget = struct { col: u16, row: u16 };
+/// The chrome a press at `col`, `row` takes (web.zig): the tag rows; then,
+/// on the cell, a pane's grip, a column's handle or a seam; then a cell
+/// away, any of a pane's tag, a handle or a seam.
pub fn chromeTarget(p: *const Pardes, col: u16, row: u16) ?ChromeTarget {
if (row < p.topBarHeight() + p.columnBarHeight()) return .{ .col = col, .row = row };
- for (p.panes, 0..) |slot, id| {
- const pane = slot orelse continue;
- const rect = p.rects[id];
- const tag = p.tagTop(pane, rect);
- if (row >= tag and row < tag + pane.tag_rows and col >= rect.x and col < rect.x + rect.w and col < rect.x + config.GUTTER)
- return .{ .col = col, .row = row };
- }
- for (0..p.ncol -| 1) |column| {
- const handle = p.col_x[column] + p.col_w[column] -| 1;
- if (col == handle) return .{ .col = handle, .row = row };
- }
- for (0..p.ncol) |column| {
- if (col < p.col_x[column] or col >= p.col_x[column] + p.col_w[column]) continue;
- for (0..p.col_n[column] -| 1) |index| {
- const rect = p.rects[p.col_panes[column][index]];
- const handle = if (p.settings.tag_bottom) rect.y +| rect.h else rect.y + rect.h -| 1;
- if (row == handle) return .{ .col = col, .row = handle };
+ for ([_]u16{ 0, 1 }) |slack| {
+ for (p.panes, 0..) |slot, id| {
+ const pane = slot orelse continue;
+ const rect = p.rects[id];
+ const tag = p.tagTop(pane, rect);
+ const edge = if (slack == 0) rect.x + config.GUTTER else rect.x + rect.w;
+ if (row >= tag and row < tag + pane.tag_rows and col >= rect.x and col < rect.x + rect.w and col < edge)
+ return .{ .col = col, .row = row };
}
- }
- for (p.panes, 0..) |slot, id| {
- const pane = slot orelse continue;
- const rect = p.rects[id];
- const tag = p.tagTop(pane, rect);
- if (row >= tag and row < tag + pane.tag_rows and col >= rect.x and col < rect.x + rect.w)
- return .{ .col = col, .row = row };
- }
- for (0..p.ncol -| 1) |column| {
- const handle = p.col_x[column] + p.col_w[column] -| 1;
- if (@max(col, handle) - @min(col, handle) == 1) return .{ .col = handle, .row = row };
- }
- for (0..p.ncol) |column| {
- if (col < p.col_x[column] or col >= p.col_x[column] + p.col_w[column]) continue;
- for (0..p.col_n[column] -| 1) |index| {
- const rect = p.rects[p.col_panes[column][index]];
- const handle = if (p.settings.tag_bottom) rect.y +| rect.h else rect.y + rect.h -| 1;
- if (@max(row, handle) - @min(row, handle) == 1) return .{ .col = col, .row = handle };
+ for (0..p.ncol -| 1) |column| {
+ const handle = p.col_x[column] + p.col_w[column] -| 1;
+ if (@max(col, handle) - @min(col, handle) == slack) return .{ .col = handle, .row = row };
+ }
+ for (0..p.ncol) |column| {
+ if (col < p.col_x[column] or col >= p.col_x[column] + p.col_w[column]) continue;
+ for (0..p.col_n[column] -| 1) |index| {
+ const seam = seamRowOf(p, column, index);
+ if (@max(row, seam) - @min(row, seam) == slack) return .{ .col = col, .row = seam };
+ }
}
}
return null;
}
+test "a press near chrome takes it: the tag rows, a column's handle or a seam on its cell or a cell away, a pane's tag; nothing in a body" {
+ if (platform == .web) return;
+ const p = try cornerFixture(std.testing.allocator);
+ defer p.deinit();
+ // Column 0's two panes share its rows evenly; column 1's lower one is
+ // tall, its middle a body row.
+ const handle = p.col_x[0] + p.col_w[0] - 1;
+ const seam = seamRowOf(p, 0, 0);
+ const mid = p.col_x[0] + p.col_w[0] / 2;
+ const top = p.rects[p.col_panes[0][0]].y;
+ const low = p.rects[p.col_panes[1][1]];
+ const body = low.y + low.h / 2;
+ try std.testing.expectEqual(ChromeTarget{ .col = 5, .row = 0 }, chromeTarget(p, 5, 0).?);
+ try std.testing.expectEqual(ChromeTarget{ .col = handle, .row = body }, chromeTarget(p, handle, body).?);
+ try std.testing.expectEqual(ChromeTarget{ .col = handle, .row = body }, chromeTarget(p, handle + 1, body).?);
+ try std.testing.expectEqual(ChromeTarget{ .col = mid, .row = seam }, chromeTarget(p, mid, seam).?);
+ try std.testing.expectEqual(ChromeTarget{ .col = mid, .row = seam }, chromeTarget(p, mid, seam - 1).?);
+ try std.testing.expectEqual(ChromeTarget{ .col = mid, .row = top }, chromeTarget(p, mid, top).?);
+ try std.testing.expect(chromeTarget(p, mid, seam - 3) == null);
+}
+
pub fn paneAt(p: *const Pardes, col: u16, row: u16) ?usize {
for (p.panes, 0..) |slot, id| {
if (slot == null) continue;