From 4f06c3ba5f985267ef589289b2b5e60220eeb4bf Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 5 Nov 2026 01:07:58 -0300 Subject: draw, gui: a tag caret's span is one Layer.caretSpan (past a full row's end it sits at the tag's right edge, where the grid's is clamped), which the core's focused cursor box and the window's caret both take, in place of the rule written in each with a comment pointing at the other Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/Layer.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/Layer.zig') diff --git a/src/Layer.zig b/src/Layer.zig index c43cab03..96250ce4 100644 --- a/src/Layer.zig +++ b/src/Layer.zig @@ -267,3 +267,13 @@ pub fn columnAt(p: *const pardes.Pardes, kind: Kind, id: usize, supplied: ?TagHi } return if (p.reprojectTagHit(point)) |mapped| mapped.col else null; } + +/// A tag caret `w` wide at glyph `x`, its left and right edges in the unit +/// `cell` (a grid cell's width) is in, glyphs `pitch` apart: past a full +/// row's end it sits at the tag's right edge, where the grid's is clamped. +pub fn caretSpan(layer: *const Layer, x: u16, cell: f32, pitch: f32, w: f32) [2]f32 { + const left = @as(f32, @floatFromInt(layer.viewport.x)) * cell; + const right = left + @as(f32, @floatFromInt(layer.viewport.w)) * cell; + const x0 = @min(left + @as(f32, @floatFromInt(x)) * pitch, right - w); + return .{ x0, @min(right, x0 + w) }; +} -- cgit v1.3