diff options
Diffstat (limited to 'core/mouse.zig')
| -rw-r--r-- | core/mouse.zig | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/core/mouse.zig b/core/mouse.zig index b62cec7e..568470c7 100644 --- a/core/mouse.zig +++ b/core/mouse.zig @@ -365,11 +365,14 @@ fn emulateButton(p: *Pardes, m: *Mouse) void { fn headerPoint(p: *Pardes, column: ?usize, mcol: u16, mrow: u16, clamp: bool) ?struct { t: *panes.Text, text: []const u8, line: u16, at: usize } { const v = p.view(); const t = if (column) |c| &v.col_tags[c] else &p.global_tag; - const x = if (column) |c| v.col_x[c] + TAG_TEXT_INSET else TAG_TEXT_INSET; + // A lone column's tag is at the window row's left, the window's at + // its right end (UX K'2). + const in_row = column == null or layout.columnInWindowRow(p); + const x = if (column) |c| (if (in_row) TAG_TEXT_INSET else v.col_x[c] + TAG_TEXT_INSET) else tagline.windowRow(p).words; const focused = v.header != null and p.headerColumn() == column; const text = edit.flatSurface(p.editor(), t) catch return null; - const base = if (column != null) p.topBarHeight() else 0; - const rows = if (column != null) layout.columnBarHeight(p) else p.topBarHeight(); + const base = if (in_row) 0 else p.topBarHeight(); + const rows = if (in_row) p.topBarHeight() else layout.columnBarHeight(p); const row: u16 = if (clamp) @min(mrow -| base, rows -| 1) else mrow -| base; const top: usize = if (focused) v.header_top else 0; const lines = modal.lineCount(text); @@ -680,7 +683,12 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { var column: ?usize = null; var x: u16 = TAG_TEXT_INSET; if (mcol < x) return; - if (mrow >= p.topBarHeight()) { + if (mrow < p.topBarHeight()) { + // The window row: a lone column's tag at its left, the + // window's at its right; the blank between them is no one's. + const sides = tagline.windowRow(p); + if (mcol < TAG_TEXT_INSET + sides.column) column = 0 else if (mcol < sides.words) return; + } else { for (0..p.view().ncol) |c| if (mcol >= v.col_x[c] and mcol < v.col_x[c] + v.col_w[c]) { column = c; x = v.col_x[c] + TAG_TEXT_INSET; @@ -1991,3 +1999,39 @@ test "a body press, drag and release are the same state whichever frame this pro } try expectSame(a, b, "after the press"); } + +fn clickAt(p: *Pardes, button: pardes.Mouse.Button, col: u16, row: u16) void { + p.update(.{ .mouse = .{ .button = button, .kind = .press, .col = col, .row = row } }); + p.update(.{ .mouse = .{ .button = button, .kind = .release, .col = col, .row = row } }); +} + +test "one column's words at the window row's left and the window's at its right each run their own; the blank between is no one's (UX K'2)" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 20, .tty_only = true }); + defer p.deinit(); + _ = try p.setTestFile("one\n"); + const row = tagline.windowRow(p); + // `New Term ` and its caret's cell from the inset; the window's words + // end on the blank before the last cell. + try std.testing.expectEqual(@as(u16, "New Term ".len + 1), row.column); + try std.testing.expectEqual(@as(u16, 100 - "Find Grep Newcol Help Exit ".len - 1), row.words); + // B2 on `New`: a pane in the column. + clickAt(p, .middle, TAG_TEXT_INSET + 1, 0); + try std.testing.expectEqual(@as(usize, 2), p.view().cols[0].n); + // B2 and B1 on the blank between: nothing, and no tag takes the keyboard. + const between = row.words - 2; + try std.testing.expect(between > TAG_TEXT_INSET + row.column); + clickAt(p, .middle, between, 0); + clickAt(p, .left, between, 0); + try std.testing.expectEqual(@as(usize, 2), p.view().cols[0].n); + try std.testing.expectEqual(@as(usize, 1), p.view().ncol); + try std.testing.expect(p.view().header == null); + // B1 on `Term`: the column's tag has the keyboard, there in the window + // row, its caret on the clicked cell. + clickAt(p, .left, TAG_TEXT_INSET + "New ".len + 1, 0); + p.sync(); + try std.testing.expectEqual(@as(?usize, 0), p.headerColumn()); + try std.testing.expectEqual(@as(i32, "New ".len + 1), p.view().col_tags[0].cur_col); + // B2 on `Newcol`, at the right: a second column. + clickAt(p, .middle, row.words + @as(u16, "Find Grep ".len) + 2, 0); + try std.testing.expectEqual(@as(usize, 2), p.view().ncol); +} |
