diff options
Diffstat (limited to 'src/tagline.zig')
| -rw-r--r-- | src/tagline.zig | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/tagline.zig b/src/tagline.zig index c057772d..79c2c09b 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -11,6 +11,7 @@ const exec = @import("exec.zig"); const config = @import("config.zig"); const pdf_enabled = panes.Pdf.enabled; const dump = @import("dump.zig"); +const Layer = @import("Layer.zig"); const Pane = panes.Pane; const Text = panes.Text; const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET; @@ -444,6 +445,46 @@ pub fn headerSelection(t: *const Text, text: []const u8, row: usize) ?struct { l return .{ .lo = @max(lo, start) - start, .hi = @min(hi, end) - start }; } +/// Whether the workspace tag is blank at cell (col, row): its inset left of +/// the text, or past the text's end with two cells kept free for the caret +/// (a B1 there still types at the end of the tag). A pixel shell lets the +/// window be dragged by such a cell, as a browser by the space beside its +/// tabs: blank is no text, so no button of acme's is taken from any. A +/// column's tag and a pane's are not: their blank is where B1 types. +pub fn workspaceBlank(p: *Pardes, col: u16, row: u16, tag_hit: ?pardes.TagHit) bool { + if (row >= p.topBarHeight() or col >= p.screen_w) return false; + if (col < TAG_TEXT_INSET) return true; + const text = edit.flatSurface(p, &p.global_tag) catch return false; + const scroll: usize = if (p.header_focus and p.header_column == null) p.header_scroll else 0; + const at = @as(usize, Layer.columnAt(p, .workspace, 0, tag_hit, false, 0) orelse (col - TAG_TEXT_INSET)) + scroll; + return at >= panes.File.displayWidth(modal.lineSlice(text, 0)) + 2; +} + +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(); + p.global_tag.own = try p.gpa.dupe(u8, "Newcol Exit"); + p.sync(); + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + _ = try p.render(arena.allocator()); + const end = TAG_TEXT_INSET + "Newcol Exit".len; + try std.testing.expect(workspaceBlank(p, 0, 0, null)); + try std.testing.expect(workspaceBlank(p, TAG_TEXT_INSET - 1, 0, null)); + // Every cell of the text, the gap between its words too, is not. + for (TAG_TEXT_INSET..end) |c| try std.testing.expect(!workspaceBlank(p, @intCast(c), 0, null)); + // The two cells after it are the caret's, then blank to the edge. + try std.testing.expect(!workspaceBlank(p, end, 0, null)); + try std.testing.expect(!workspaceBlank(p, end + 1, 0, null)); + try std.testing.expect(workspaceBlank(p, end + 2, 0, null)); + try std.testing.expect(workspaceBlank(p, 79, 0, null)); + // Below the workspace tag: a column's tag, a pane: never. + for (1..12) |r| try std.testing.expect(!workspaceBlank(p, 79, @intCast(r), null)); + // Hidden, there is none. + p.settings.workspace_tag = false; + 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. |
