diff options
Diffstat (limited to 'src/tagline.zig')
| -rw-r--r-- | src/tagline.zig | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/src/tagline.zig b/src/tagline.zig index b9abf5f0..a7438be3 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -449,6 +449,40 @@ pub fn workspaceBlank(p: *Pardes, col: u16, row: u16, tag_hit: ?pardes.TagHit) b return at >= panes.File.displayWidth(modal.lineSlice(text, 0)) + 2; } +/// Column and workspace tags are one line, as acme's: a newline typed, +/// pasted or restored from a dump into one becomes a space, the caret and +/// the selection kept on the same characters. +pub fn flattenHeaders(p: *Pardes) void { + for (p.view().col_tags[0..p.view().ncol]) |*t| flatten(t); + flatten(&p.global_tag); +} + +fn flatten(t: *Text) void { + const own = t.own orelse return; + if (std.mem.indexOfScalar(u8, own, '\n') == null) return; + const cur = modal.offsetAt(own, .{ .row = @intCast(@max(0, t.cur_row)), .col = @intCast(@max(0, t.cur_col)) }); + const anchor = modal.offsetAt(own, .{ .row = @intCast(@max(0, t.vsel.row)), .col = @intCast(@max(0, t.vsel.col)) }); + std.mem.replaceScalar(u8, own, '\n', ' '); + t.cur_row = 0; + t.cur_col = @intCast(cur); + t.vsel.row = 0; + t.vsel.col = @intCast(anchor); + t.nsel = 0; +} + +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 }; +} + test "the workspace tag is blank left of its text and past its end, and nowhere else" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 12, .tty_only = true }); defer p.deinit(); @@ -474,27 +508,6 @@ test "the workspace tag is blank left of its text and past its end, and nowhere try std.testing.expect(!workspaceBlank(p, 79, 0, null)); } -/// Column and workspace tags are one line, as acme's: a newline typed, -/// pasted or restored from a dump into one becomes a space, the caret and -/// the selection kept on the same characters. -pub fn flattenHeaders(p: *Pardes) void { - for (p.view().col_tags[0..p.view().ncol]) |*t| flatten(t); - flatten(&p.global_tag); -} - -fn flatten(t: *Text) void { - const own = t.own orelse return; - if (std.mem.indexOfScalar(u8, own, '\n') == null) return; - const cur = modal.offsetAt(own, .{ .row = @intCast(@max(0, t.cur_row)), .col = @intCast(@max(0, t.cur_col)) }); - const anchor = modal.offsetAt(own, .{ .row = @intCast(@max(0, t.vsel.row)), .col = @intCast(@max(0, t.vsel.col)) }); - std.mem.replaceScalar(u8, own, '\n', ' '); - t.cur_row = 0; - t.cur_col = @intCast(cur); - t.vsel.row = 0; - t.vsel.col = @intCast(anchor); - t.nsel = 0; -} - test "a column or workspace tag is one line: a newline in it is a space" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 50, .rows = 12, .tty_only = true }); defer p.deinit(); @@ -520,16 +533,3 @@ 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 }; -} |
