diff options
Diffstat (limited to 'core/body_layer.zig')
| -rw-r--r-- | core/body_layer.zig | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/core/body_layer.zig b/core/body_layer.zig index 1eb3bf54..a1d76784 100644 --- a/core/body_layer.zig +++ b/core/body_layer.zig @@ -373,6 +373,17 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane const show_prim = (pane.body.mode == .normal and pane.body.vsel.active) or preview or (modal_hover and pane.body.vsel.active); const show_extra = pane.body.mode != .tty and pane.body.nsel > 0; + // The primary selection that is the current place (a live `/`, `n`, a + // preview select it) is drawn as that place, its solid chip, not the + // selection: one meaning, one look; the caret still shows. + const on_place = place: { + const f = pane.file orelse break :place false; + const at = pane.places.current orelse break :place false; + if (!pane.places.shows(pane) or at >= pane.places.hits.items.len) break :place false; + const range = pane.body.primaryRange(f.content, 0); + const hit = pane.places.hits.items[at]; + break :place hit.start == @min(range.anchor, range.head) and hit.end == @max(range.anchor, range.head); + }; if (show_prim or show_extra) { const vpfx: i32 = if (pane.file != null) panes.File.gutterWidth(pane) else 0; var si: usize = 0; @@ -394,6 +405,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane const bg = if (full) c.page.selection.ground else c.selection_secondary; var vr: i32 = 0; while (vr + @as(i32, pane.tag_rows) < @as(i32, body_bottom)) : (vr += 1) { + if (primary and on_place) break; const w = pane.wrapAt(p.settings.tab, vr); if (w.line < bnd.lo_row or w.line > bnd.hi_row) continue; const visible_line = modal.lineSlice(body, @intCast(vr)); @@ -1471,3 +1483,42 @@ test "the body's surfaces take every colour from the chrome: none reads a theme' } try std.testing.expectEqual(@as(usize, 0), wrong); } + +test "a selection that is the current place is drawn as the current place, its solid chip, not the selection: one meaning, one look (the coordinator's ruling on L2b's open point); the caret still shows, and any other selection is the selection" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + colors.setThemeIndex(p, colors.themeIndex("orchard").?); + const pane = try p.setTestFile("alpha beta\ngamma alpha\nb\n"); + const c = p.chrome(); + var frame: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer frame.deinit(); + const r = p.view().rects[0]; + const x = r.x + config.GUTTER + panes.File.gutterWidth(pane); + const y = p.bodyTop(pane, r); + const keys = struct { + fn typed(q: *Pardes, text: []const u8) void { + for (text) |ch| q.update(.{ .key = .{ .cp = ch, .text = &[_]u8{ch} } }); + } + }.typed; + // A live `/`: the first place current, and selected. + keys(p, "/alpha"); + try std.testing.expectEqual(@as(?usize, 0), pane.places.current); + var s = try p.render(frame.allocator()); + for (0..5) |i| { + const cell = s.at(x + @as(u16, @intCast(i)), y).style; + try std.testing.expectEqual(Color{ .rgb = c.hit_current }, cell.bg); + try std.testing.expectEqual(Color{ .rgb = c.hit_current_text }, cell.fg); + } + // Landed, then `n`: the next one current and selected, the same chip, + // and the caret on it. + p.update(.{ .key = .{ .cp = pardes.Key.enter } }); + keys(p, "n"); + try std.testing.expectEqual(@as(?usize, 1), pane.places.current); + s = try p.render(frame.allocator()); + for (6..11) |i| try std.testing.expectEqual(Color{ .rgb = c.hit_current }, s.at(x + @as(u16, @intCast(i)), y + 1).style.bg); + try std.testing.expect(s.cursor != null and s.cursor.?.y == y + 1 and s.cursor.?.x >= x + 6 and s.cursor.?.x <= x + 10); + // The line selected, past the place: a selection again. + keys(p, "x"); + s = try p.render(frame.allocator()); + try std.testing.expectEqual(Color{ .rgb = c.page.selection.ground }, s.at(x + 6, y + 1).style.bg); +} |
