summaryrefslogtreecommitdiff
path: root/src/tagline.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/tagline.zig')
-rw-r--r--src/tagline.zig38
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());
+}
+