summaryrefslogtreecommitdiff
path: root/src/tagline.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/tagline.zig')
-rw-r--r--src/tagline.zig13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/tagline.zig b/src/tagline.zig
index 0bb0018b..3e7ebe52 100644
--- a/src/tagline.zig
+++ b/src/tagline.zig
@@ -518,3 +518,16 @@ test "a pane tag wraps a long line onto rows, and offsets map both ways" {
try std.testing.expectEqual(@as(usize, 10), shown.toReal(11)); // the 'e' of Del
try std.testing.expectEqual(@as(usize, 11), shown.fromReal(10));
}
+
+const WordBounds = struct { lo: usize, hi: usize };
+
+/// The space-delimited word covering `col` in `str` (a header's click and
+/// hover), null on a space or past the end.
+pub fn wordBoundsAtCol(str: []const u8, col: usize) ?WordBounds {
+ if (col >= str.len or str[col] == ' ') return null;
+ var lo: usize = col;
+ while (lo > 0 and str[lo - 1] != ' ') lo -= 1;
+ var hi: usize = col;
+ while (hi < str.len and str[hi] != ' ') hi += 1;
+ return .{ .lo = lo, .hi = hi };
+}