diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-28 19:17:12 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:15 -0300 |
| commit | 8429e7bd8aff1ae0c71d3b1a7a6b9f01ed52e691 (patch) | |
| tree | 9ae9dbe35e371a7b64b7e64bd690c4871e0b705c /src/tagline.zig | |
| parent | 4cea4751960b359561997cb040f05179923cb80e (diff) | |
| download | pardes-8429e7bd8aff1ae0c71d3b1a7a6b9f01ed52e691.tar.gz pardes-8429e7bd8aff1ae0c71d3b1a7a6b9f01ed52e691.zip | |
Column and workspace tags are one line again, as acme's
acme gives a column tag one font height (cols.c:244) and its row tag one line; pardes let them grow a row per line. A newline typed, pasted, written or restored into a column or workspace tag now becomes a space, the caret and selection kept on the same characters, and the bars are one row each. A dump holding a multi-line header tag comes back with its lines joined by spaces.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/tagline.zig')
| -rw-r--r-- | src/tagline.zig | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/tagline.zig b/src/tagline.zig index 59c51b4d..858bb9b1 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -453,3 +453,41 @@ pub fn headerSelection(t: *const Text, text: []const u8, row: usize) ?struct { l if (hi <= start or lo >= end) return null; return .{ .lo = @max(lo, start) - start, .hi = @min(hi, end) - start }; } + +/// 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.col_tags[0..p.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(); + p.col_tags[0].own = try p.gpa.dupe(u8, "New\nSnarf"); + p.col_tags[0].cur_row = 1; + p.col_tags[0].cur_col = 2; + p.global_tag.own = try p.gpa.dupe(u8, "Newcol\nExit"); + p.sync(); + try std.testing.expectEqualStrings("New Snarf", columnTag(p, 0)); + try std.testing.expectEqualStrings("Newcol Exit", p.global_tag.own.?); + try std.testing.expectEqual(@as(i32, 0), p.col_tags[0].cur_row); + try std.testing.expectEqual(@as(i32, 6), p.col_tags[0].cur_col); + try std.testing.expectEqual(pardes.COLBAR_H, p.columnBarHeight()); + try std.testing.expectEqual(pardes.TOPBAR_H, p.topBarHeight()); +} + |
