diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Query.zig | 75 | ||||
| -rw-r--r-- | src/body_layer.zig | 1 | ||||
| -rw-r--r-- | src/exec.zig | 4 |
3 files changed, 50 insertions, 30 deletions
diff --git a/src/Query.zig b/src/Query.zig index a5d33cf4..11db8579 100644 --- a/src/Query.zig +++ b/src/Query.zig @@ -1349,18 +1349,15 @@ fn clearPlaces(p: *Pardes, q: *Query, serial: u32, owner_id: ?usize, asked: anyt // ---- the current row ---- -/// The current row drawn as the visited row is (a line selection), while -/// the keyboard is on line 1 or elsewhere; on the rows, the cursor itself -/// is current. Scrolled into view, line 1 kept when it can be. +/// The current row scrolled into view while the keyboard is on line 1 or +/// elsewhere, line 1 kept when it can be. Its mark is `paint`'s, drawn +/// from `current`: no selection, so no click, sweep or chord clears it and +/// no B2 or B3 borrows it. fn showCurrent(rp: *Pane) void { const q = rp.query orelse return; if (rp.body.cur_row != 0 and rp.focus == .body) return; - const c = q.current orelse { - rp.body.msel.active = false; - return; - }; + const c = q.current orelse return; const r: i32 = @intCast(c + 1); - rp.body.msel = .{ .active = true, .r0 = r, .r1 = r }; // Typed into, line 1 stays in view whatever the current row: what you // type is never scrolled away (the live rows start just before the // current one, so it sits under line 1). Frozen, the row is scrolled to. @@ -1373,11 +1370,9 @@ fn showCurrent(rp: *Pane) void { if (r > shown) rp.scrollBy(r - shown) else if (r < off) rp.scrollBy(r - off); } -/// The caret on item `i`'s row, the row in view: the current row's own -/// mark from here (the line selection is for the caret on line 1). +/// The caret on item `i`'s row, the row in view. fn caretTo(rp: *Pane, i: usize) void { const r: i32 = @intCast(i + 1); - rp.body.msel.active = false; rp.body.cur_row = r; rp.body.cur_col = 0; rp.body.cur_pinned = true; @@ -1941,6 +1936,25 @@ pub fn tagPrefix(q: *const Query, arena: std.mem.Allocator, path: []const u8) ![ return std.fmt.allocPrint(arena, "{s} {d}/{d}{s}", .{ name, q.k, q.total, more }); } +/// The current row's mark: a tint the width of the body, painted before +/// the row's colours, so its match's tint, the places' and any selection +/// draw over it. Its own, from `current`: no click, sweep or chord clears +/// it, no B2 or B3 borrows it. +pub fn paintMark(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u16) void { + const q = pane.query orelse return; + const c = q.current orelse return; + const th = p.theme(); + const mark = colors.mix(th.bg orelse th.tag_bg, th.sel_bg); + const tx = r.x + config.GUTTER; + const tw = r.w -| config.GUTTER; + const col = File.gutterWidth(pane); + var row: i32 = 0; + while (row < body_h) : (row += 1) { + if (pane.wrapAt(row).line != @as(i32, @intCast(c + 1)) or col >= tw) continue; + s.tint(tx + col, p.bodyTop(pane, r) + @as(u16, @intCast(row)), tw - col, mark, null); + } +} + /// The other places on a hit row's line tinted, from the pane its rows are /// in (the first is the row's own mark, Output.decorateRow): the current /// one strongest, as in that pane's text. @@ -2438,7 +2452,7 @@ test "a language server's list: one answer lands with no pane, several open the try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); } -test "B1 on a query pane's rows places the caret and selects, nothing else; j, k and n make a row current, Enter lands the current" { +test "B1 on a query pane's rows places the caret and selects, nothing else, the current row's mark kept; j, k and n make a row current, Enter lands the current" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); defer p.deinit(); const pane = try p.setTestFile("alpha one\nbeta\nalphabet\ngamma alpha\nalpha two\ndelta\n"); @@ -2449,44 +2463,51 @@ test "B1 on a query pane's rows places the caret and selects, nothing else; j, k p.acknowledgePanelPresentation(&.{}); const owner_sel = pane.body.primaryRange(pane.file.?.content, 0); const owner_scroll = pane.file.?.scroll; - const current = q.current; + try std.testing.expectEqual(@as(?usize, 0), q.current); const place = pane.places.current; const r = p.rects[qid]; - const y = r.y + qp.tag_rows + 3; + const row_y = r.y + qp.tag_rows; + const y = row_y + 3; const x = r.x + config.GUTTER + File.gutterWidth(qp) + 6; // a click: the caret there, the current row and every other pane as they were p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = x, .row = y } }); p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = x, .row = y } }); try std.testing.expectEqual(@as(i32, 3), qp.body.cur_row); - try std.testing.expectEqual(current, q.current); + try std.testing.expectEqual(@as(?usize, 0), q.current); try std.testing.expectEqual(place, pane.places.current); try std.testing.expectEqual(owner_sel, pane.body.primaryRange(pane.file.?.content, 0)); try std.testing.expectEqual(owner_scroll, pane.file.?.scroll); - try std.testing.expect(p.panes[qid] != null and queryPane2(p, qid) == null); + try std.testing.expect(queryPane2(p, qid) == null); + // the current row (1) still marked, no other row (2) is + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const surf = try p.render(frame.allocator()); + const far = r.x + r.w - 2; + try std.testing.expect(!std.meta.eql(surf.at(far, row_y + 1).style.bg, surf.at(far, row_y + 2).style.bg)); // a sweep selects the text it went over, and nothing else p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = x, .row = y } }); p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = x + 4, .row = y } }); p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = x + 4, .row = y } }); const swept = qp.sel[@backingInt(config.select_button)]; try std.testing.expect(swept.state == .done and swept.r0 == swept.r1 and swept.c1 - swept.c0 == 4); - try std.testing.expectEqual(current, q.current); + try std.testing.expectEqual(@as(?usize, 0), q.current); try std.testing.expectEqual(owner_sel, pane.body.primaryRange(pane.file.?.content, 0)); - // the keyboard: j onto the next row makes it current, the text follows + // the keyboard: n steps from the current row, not the caret's, the caret with it p.active = qid; if (qp.body.mode == .insert) p.update(.{ .key = .{ .cp = Key.escape } }); try std.testing.expect(p.panes[qid] != null); - typeKeys(p, "j"); - try std.testing.expectEqual(@as(i32, 4), qp.body.cur_row); - try std.testing.expectEqual(@as(?usize, 3), pane.places.current); - // n round the end: the caret goes with the current row typeKeys(p, "n"); - try std.testing.expectEqual(@as(?usize, 0), pane.places.current); - try std.testing.expectEqual(@as(i32, 1), qp.body.cur_row); + try std.testing.expectEqual(@as(?usize, 1), pane.places.current); + try std.testing.expectEqual(@as(i32, 2), qp.body.cur_row); + // j onto the next row makes it current, the text following + typeKeys(p, "j"); + try std.testing.expectEqual(@as(i32, 3), qp.body.cur_row); + try std.testing.expectEqual(@as(?usize, 2), pane.places.current); // B1 elsewhere, then Enter: the current row lands, not the caret's - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = x, .row = y } }); - p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = x, .row = y } }); + p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = x, .row = row_y + 1 } }); + p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = x, .row = row_y + 1 } }); p.active = qid; p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expectEqual(@as(usize, 0), p.active); - try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); + try std.testing.expectEqual(@as(i32, 3), pane.body.cur_row); } diff --git a/src/body_layer.zig b/src/body_layer.zig index d4ca6d69..bfca268a 100644 --- a/src/body_layer.zig +++ b/src/body_layer.zig @@ -286,6 +286,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane // File layout is independent of whether its producer requests colors. if (pane.file) |*f| { panes.File.drawGutter(p, s, pane, r, tx, tw, body_h, active); + panes.Query.paintMark(p, s, pane, r, body_h); if (p.settings.colors and pane.colorAlgo() != .none) panes.File.recolorSyntax(p, s, pane, f, r, tx, tw, body_h); panes.Tables.paint(p, s, pane, r, tx, tw, body_h); diff --git a/src/exec.zig b/src/exec.zig index 7248632b..5b0eb204 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -182,9 +182,7 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l result.text = edit.currentSelText(p, pane); return result; } - // A query pane's line selection is its current row's mark, not a - // selection made: a click on that row takes its word, as on any row. - if (pane.body.msel.active and pane.query == null and row >= @min(pane.body.msel.r0, pane.body.msel.r1) and + if (pane.body.msel.active and row >= @min(pane.body.msel.r0, pane.body.msel.r1) and row <= @max(pane.body.msel.r0, pane.body.msel.r1)) { result.text = edit.currentSelText(p, pane); |
