diff options
Diffstat (limited to 'core')
42 files changed, 622 insertions, 610 deletions
diff --git a/core/Addon.zig b/core/Addon.zig index 5c3f84e2..5c23ed51 100644 --- a/core/Addon.zig +++ b/core/Addon.zig @@ -342,11 +342,11 @@ fn listed(data: []const u8, path: []const u8, n: usize, why: *Why) Loaded { /// Kind `k`'s code, a session's (a replica's is `plainOps`'s or none): its /// library loaded at the first pane of its kind, from the file the start /// listed it from (`listed`); null, and why, when it will not load. -pub fn need(r: *Kind.Registry, k: u8, why: *Why) ?*const Kind.Ops { +pub fn need(r: *Kind.Registry, k: u8, why: *Why, distrusted: ?*const Distrusted) ?*const Kind.Ops { if (r.ops[k] != null) return r.ops[k]; // A client's: its own code for a plain kind, loaded at its first pane. if (tape.replaying()) { - r.ops[k] = plainOps(&r.kinds[k]); + r.ops[k] = plainOps(&r.kinds[k], distrusted); return r.ops[k]; } const e = &r.kinds[k]; @@ -551,12 +551,13 @@ pub fn loadedOf(ops: *const Kind.Ops, path: []const u8, hash: [32]u8, words: *[6 /// This process's code for a kind a session's core lists, which a client /// runs itself: PA_PLAIN, of the same name, version, ABI and functions (a /// compiled-in addon's library hash is 0: never by the hash), and not -/// caught breaking its promise here (`distrust`). Null: its panes say so. -pub fn plainOps(e: *const Kind.Entry) ?*const Kind.Ops { +/// caught breaking its promise here (`distrusted`, the client's). Null: its +/// panes say so. +pub fn plainOps(e: *const Kind.Entry, distrusted: ?*const Distrusted) ?*const Kind.Ops { if (!e.caps.plain or e.refused) return null; // A client scans for its addons only when its session has a plain kind. _ = scan(); - for (distrusted[0..ndistrusted]) |*d| if (std.mem.eql(u8, std.mem.sliceTo(d, 0), e.nameOf())) return null; + if (distrusted) |d| for (d.names[0..d.n]) |*name| if (std.mem.eql(u8, std.mem.sliceTo(name, 0), e.nameOf())) return null; for (found[0..nfound], 0..) |*l, i| if (l.why.len == 0 and std.mem.eql(u8, l.name, e.nameOf()) and l.version == e.version and l.abi == e.abi and @as(u16, @bitCast(l.caps)) == @as(u16, @bitCast(e.caps))) { @@ -568,16 +569,20 @@ pub fn plainOps(e: *const Kind.Entry) ?*const Kind.Ops { } /// Kinds a client found breaking PA_PLAIN: shown by the session's line -/// from its next join on. A process's (test/replicas.zig keeps one a client). -pub var distrusted: [Kind.max_kinds][16]u8 = undefined; -pub var ndistrusted: usize = 0; +/// from its next join on. The client's, which outlives each core it joins +/// with (its frontend's, handed to them as `Options.distrusted`): no core's +/// state, never rolled back. +pub const Distrusted = struct { + names: [Kind.max_kinds][16]u8 = undefined, + n: usize = 0, -pub fn distrust(name: []const u8) void { - if (ndistrusted == distrusted.len) return; - distrusted[ndistrusted] = @splat(0); - @memcpy(distrusted[ndistrusted][0..@min(15, name.len)], name[0..@min(15, name.len)]); - ndistrusted += 1; -} + pub fn add(d: *Distrusted, name: []const u8) void { + if (d.n == d.names.len) return; + d.names[d.n] = @splat(0); + @memcpy(d.names[d.n][0..@min(15, name.len)], name[0..@min(15, name.len)]); + d.n += 1; + } +}; /// The kind that opens `path`, by its extension (any case). pub fn forPath(r: *const Kind.Registry, path: []const u8) ?u8 { diff --git a/core/Core.zig b/core/Core.zig index 39d09f21..a19453af 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -523,8 +523,6 @@ pub fn init(gpa: std.mem.Allocator, opts: Options) !*Pardes { } fn initSession(gpa: std.mem.Allocator, opts: Options) !*Pardes { - // A new session draws a tab at the default until `Tab` says otherwise. - config.tab_now = config.tab_width; const p = try create(gpa, opts); errdefer p.deinit(); p.boot = Boot.of(opts); @@ -1604,7 +1602,7 @@ pub fn update(p: *Pardes, ev: Event) void { .tick => { Stream.step(p); Messages.advanceMessages(p); - for (p.panes) |slot| if (slot) |pane| if (pane.file) |*f| f.tables.step(pane.gpa, f); + for (p.panes) |slot| if (slot) |pane| if (pane.file) |*f| f.tables.step(p.settings.tab, pane.gpa, f); for (0..p.panes.len) |id| exec.flushReplEnter(p, id, false); }, else => {}, @@ -1858,7 +1856,7 @@ pub fn sync(p: *Pardes) void { var caret_row: usize = @intCast(@max(0, pane.tag.cur_row)); if (prefix) |made| wrap: { const whole = std.mem.concat(wa, u8, &.{ made, tagline.curTail(pane) }) catch break :wrap; - const shown = tagline.wrapTag(wa, whole, tagline.tagWidth(p, id)) catch break :wrap; + const shown = tagline.wrapTag(p.settings.tab, wa, whole, tagline.tagWidth(p, id)) catch break :wrap; lines = shown.rows(); // Collapsed, one row, as acme's Tagup sets taglines to 1 // (plan9port text.c:786). @@ -2174,6 +2172,7 @@ pub const Boot = enum { }; pub const Options = struct { + pub const replica = .{ .local = .{"distrusted"} }; tty_only: bool = false, /// The first view's frontend is a window (`Pardes.frontend`), as a /// window's build says: an option, taped with the rest, so that a @@ -2215,6 +2214,9 @@ pub const Options = struct { recent_import: ?[]const u8 = null, startup_config_path: ?[]const u8 = null, image_allocator: ?std.mem.Allocator = null, + /// A client's: the kinds it caught breaking PA_PLAIN, its frontend's + /// list, which outlives each core it joins with. In no tape and no dump. + distrusted: ?*pardes.Addon.Distrusted = null, /// What the host's scan of the addon directories found (Addon.scan). addons: []const pardes.Kind.Loaded = &.{}, tree_sitter_allocator: ?std.mem.Allocator = null, @@ -2923,7 +2925,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe // Several selections executed at once: each is sent, not the first. { const text = try edit.flatSurface(p.editor(), &file.body); - file.body.setRanges(text, &.{ .{ .anchor = 0, .head = 8 }, .{ .anchor = 9, .head = 11 } }, &.{}, 0, true); + file.body.setRanges(config.tab_width, text, &.{ .{ .anchor = 0, .head = 8 }, .{ .anchor = 9, .head = 11 } }, &.{}, 0, true); try std.testing.expect(exec.chordEachSel(p, file, .Exec)); Sent.drain(p); try std.testing.expectEqualStrings("print(1)\rls\r", Sent.said(1)); @@ -3438,11 +3440,9 @@ test "Tab N draws every pane's tab N cells wide and clicks count past it; bare T const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .cols = 60, .rows = 12 }); defer p.deinit(); - // The width is the process's: the next test starts from the default. - defer config.tab_now = config.tab_width; const pane = try p.setTestFile("\tx = 1\n"); try std.testing.expect(p.executeBuiltinLine(0, "Tab 8")); - try std.testing.expectEqual(@as(u16, 8), config.tab_now); + try std.testing.expectEqual(@as(u16, 8), p.settings.tab); var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); const surface = try p.render(frame.allocator()); @@ -3459,7 +3459,7 @@ test "Tab N draws every pane's tab N cells wide and clicks count past it; bare T try std.testing.expectEqualStrings("Tab 8", pane.msg[0..pane.msg_len]); // Out of range: refused, the width kept. try std.testing.expect(p.executeBuiltinLine(0, "Tab 0")); - try std.testing.expectEqual(@as(u16, 8), config.tab_now); + try std.testing.expectEqual(@as(u16, 8), p.settings.tab); // The ctl read's tab column, and a Dump's settings. const ctl_text = @import("ninep/testing.zig").rd(p, ctlfs.Node.of(pane.serial, .ctl), 0, 4096).bytes; try std.testing.expect(std.mem.indexOf(u8, ctl_text, " 8 ") != null); @@ -3467,7 +3467,6 @@ test "Tab N draws every pane's tab N cells wide and clicks count past it; bare T const restored = try dump.restore(p, p.dump_out.?, "/tmp/pardes.dump.zon"); defer restored.deinit(); try std.testing.expectEqual(@as(u16, 8), restored.settings.tab); - try std.testing.expectEqual(@as(u16, 8), config.tab_now); } test "tabbed file aligns syntax cursor and mouse at the nearest insertion gap" { @@ -3504,7 +3503,7 @@ test "tabbed file aligns syntax cursor and mouse at the nearest insertion gap" { const line = modal.lineSlice(f.content, 0); const virtual: u16 = 3; - const blank_x = text_x + @as(u16, @intCast(pardes.panes.File.displayWidth(line))) + virtual; + const blank_x = text_x + @as(u16, @intCast(pardes.panes.File.displayWidth(config.tab_width, line))) + virtual; p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = blank_x, .row = body_y } }); p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = blank_x, .row = body_y } }); try std.testing.expectEqual(@as(i32, @intCast(line.len)), pane.body.cur_col); @@ -3518,7 +3517,7 @@ test "tabbed file aligns syntax cursor and mouse at the nearest insertion gap" { // The immediately-adjacent EOL cell and an in-line separator are blank // too. Pointer expansion must not lean left into the preceding word. - const adjacent: i32 = @intCast(config.PREFIX_W + pardes.panes.File.displayWidth(line)); + const adjacent: i32 = @intCast(config.PREFIX_W + pardes.panes.File.displayWidth(config.tab_width, line)); try std.testing.expect(look.expandedSel(p, pane, .{ .state = .dragging, .c0 = adjacent, .c1 = adjacent, .r0 = BOX_H, .r1 = BOX_H }) == null); const separator: i32 = @intCast(config.PREFIX_W + config.tab_width + "return".len); try std.testing.expect(look.expandedSel(p, pane, .{ .state = .dragging, .c0 = separator, .c1 = separator, .r0 = BOX_H, .r1 = BOX_H }) == null); @@ -3986,7 +3985,7 @@ test "leaving tty hides the prompt and keeps the command typed at it" { }.at; const bodyRowOf = struct { fn at(pp: *Pardes, pane: *Pane, needle: []const u8) ?[]const u8 { - const body = @import("body_layer.zig").bodyText(pp.scratch.allocator(), pane) catch return null; + const body = @import("body_layer.zig").bodyText(pp.settings.tab, pp.scratch.allocator(), pane) catch return null; var it = std.mem.splitScalar(u8, body, '\n'); while (it.next()) |r| if (std.mem.indexOf(u8, r, needle) != null) return r; return null; diff --git a/core/Dir.zig b/core/Dir.zig index 0f99e497..1be67378 100644 --- a/core/Dir.zig +++ b/core/Dir.zig @@ -105,10 +105,10 @@ fn readHost(gpa: std.mem.Allocator, local: []const u8) ![]u8 { /// first, every column as wide as the widest entry and a cell more, /// rounded up to a tab, and each row ending in a newline. Blanks pad where /// acme's tabs do: a pardes tab is a fixed width, not a stop. -pub fn columnate(gpa: std.mem.Allocator, entries: []const []const u8, width: usize) error{OutOfMemory}![]u8 { +pub fn columnate(tab_w: u16, gpa: std.mem.Allocator, entries: []const []const u8, width: usize) error{OutOfMemory}![]u8 { var colw: usize = 0; for (entries) |entry| { - const w = File.displayWidth(entry) + 1; + const w = File.displayWidth(tab_w, entry) + 1; colw = @max(colw, (w + tab - 1) / tab * tab); } const ncol = if (colw == 0) 1 else @max(1, width / colw); @@ -120,7 +120,7 @@ pub fn columnate(gpa: std.mem.Allocator, entries: []const []const u8, width: usi while (j < entries.len) : (j += nrow) { try out.appendSlice(gpa, entries[j]); if (j + nrow >= entries.len) break; - try out.appendNTimes(gpa, ' ', colw - File.displayWidth(entries[j])); + try out.appendNTimes(gpa, ' ', colw - File.displayWidth(tab_w, entries[j])); } try out.append(gpa, '\n'); } @@ -151,7 +151,7 @@ pub fn fit(p: *Pardes, pane: *Pane, cols: usize) void { defer p.gpa.free(entries); var it = std.mem.splitScalar(u8, l.names, '\n'); for (entries) |*entry| entry.* = it.next().?; - const text = columnate(p.gpa, entries, width) catch return; + const text = columnate(p.settings.tab, p.gpa, entries, width) catch return; if (std.mem.eql(u8, text, f.content)) p.gpa.free(text) else { File.setContent(p, f, text); panes.Output.resetBody(p, pane); @@ -252,7 +252,7 @@ pub fn show(p: *Pardes, from: usize, id: usize) void { const testing = std.testing; fn laidOut(names: []const []const u8, width: usize) ![]u8 { - return columnate(testing.allocator, names, width); + return columnate(config.tab_width, testing.allocator, names, width); } test "entries go down each column first, a column a tab wider than its widest entry, as acme's" { diff --git a/core/Editor.zig b/core/Editor.zig index 5b1fc6e2..82c93640 100644 --- a/core/Editor.zig +++ b/core/Editor.zig @@ -45,6 +45,9 @@ multi_count: *usize, retired_edit: *?[]u8, /// The core the text's pane is in: what an edit reaches past its text with. p: if (lib) void else *Pardes, +/// A tab's width in cells (the core's `settings.tab`; the library's, the +/// default). +tab: u16, /// The library's: an edit failed (its allocator ran out) and the key is /// refused. failed: if (lib) *bool else void, @@ -64,6 +67,7 @@ pub fn of(p: *Pardes) Editor { .multi_count = &p.multi_count, .retired_edit = &p.retired_edit, .p = p, + .tab = p.settings.tab, .failed = {}, .syntax = {}, }; diff --git a/core/File.zig b/core/File.zig index 2e5a8306..b21dac78 100644 --- a/core/File.zig +++ b/core/File.zig @@ -183,9 +183,9 @@ pub const State = struct { pub const NodeStep = @import("Editor.zig").NodeStep; -pub fn graphemeDisplayWidth(grapheme: []const u8) usize { - if (std.mem.eql(u8, grapheme, "\t")) return config.tab_now; +pub fn graphemeDisplayWidth(tab: u16, grapheme: []const u8) usize { if (grapheme.len == 1 and grapheme[0] >= 0x20 and grapheme[0] < 0x7f) return 1; + if (std.mem.eql(u8, grapheme, "\t")) return tab; if (std.unicode.utf8ValidateSlice(grapheme)) return @max(1, @as(usize, vaxis.gwidth.gwidth(grapheme, .unicode))); // vaxis's gwidth counts back a replacement rune's 3 bytes over the one // invalid byte it stood for (`\xee` before `e\u{301}` overflowed it): @@ -209,12 +209,12 @@ pub fn graphemeDisplayWidth(grapheme: []const u8) usize { return @max(1, width); } -pub fn displayWidth(text: []const u8) usize { +pub fn displayWidth(tab: u16, text: []const u8) usize { var width: usize = 0; var at: usize = 0; while (at < text.len) { const end = modal.nextGrapheme(text, at); - width +|= graphemeDisplayWidth(text[at..end]); + width +|= graphemeDisplayWidth(tab, text[at..end]); at = end; } return width; @@ -222,12 +222,12 @@ pub fn displayWidth(text: []const u8) usize { /// Source byte at a zero-based display column. Every cell occupied by a tab /// maps back to that one tab byte. -pub fn byteAtDisplay(text: []const u8, display_col: usize) usize { +pub fn byteAtDisplay(tab: u16, text: []const u8, display_col: usize) usize { var col: usize = 0; var at: usize = 0; while (at < text.len) { const end = modal.nextGrapheme(text, at); - const next = col +| graphemeDisplayWidth(text[at..end]); + const next = col +| graphemeDisplayWidth(tab, text[at..end]); if (display_col < next) return at; col = next; at = end; @@ -237,46 +237,46 @@ pub fn byteAtDisplay(text: []const u8, display_col: usize) usize { /// File cursor columns may live past EOL. Tabs expand before that boundary; /// every virtual column after it remains one screen cell. -pub fn rawDisplayCol(line_text: []const u8, raw_col: usize) usize { +pub fn rawDisplayCol(tab: u16, line_text: []const u8, raw_col: usize) usize { const bounded = modal.graphemeStart(line_text, @min(raw_col, line_text.len)); - return displayWidth(line_text[0..bounded]) +| (raw_col -| line_text.len); + return displayWidth(tab, line_text[0..bounded]) +| (raw_col -| line_text.len); } /// Walked only as far as the column: a row's last byte, a million bytes /// into a line, is found without measuring the rest of it. Only a line /// that ends before the column is measured whole (it is short). -pub fn rawAtDisplay(line_text: []const u8, display_col: usize) usize { - const at = byteAtDisplay(line_text, display_col); +pub fn rawAtDisplay(tab: u16, line_text: []const u8, display_col: usize) usize { + const at = byteAtDisplay(tab, line_text, display_col); if (at < line_text.len) return at; - return line_text.len +| (display_col -| displayWidth(line_text)); + return line_text.len +| (display_col -| displayWidth(tab, line_text)); } -pub fn byteAtDisplayFrom(line_text: []const u8, from_raw: usize, display_col: usize) usize { +pub fn byteAtDisplayFrom(tab: u16, line_text: []const u8, from_raw: usize, display_col: usize) usize { if (from_raw >= line_text.len) return from_raw +| display_col; const from = modal.graphemeStart(line_text, from_raw); - return from +| rawAtDisplay(line_text[from..], display_col); + return from +| rawAtDisplay(tab, line_text[from..], display_col); } /// The display columns from `from_raw` to `to_raw` on a line. Widths add /// (a tab is `tab_width` wherever it stands), so only the text between /// the two is measured, never the line from its start: a selection a /// million bytes into a line draws as fast as one at its start. -pub fn lineDisplayOffset(line_text: []const u8, from_raw: usize, to_raw: usize) i32 { +pub fn lineDisplayOffset(tab: u16, line_text: []const u8, from_raw: usize, to_raw: usize) i32 { const lo = @min(from_raw, to_raw); const hi = @max(from_raw, to_raw); const a = modal.graphemeStart(line_text, @min(lo, line_text.len)); const b = modal.graphemeStart(line_text, @min(hi, line_text.len)); const past = (hi -| line_text.len) - (lo -| line_text.len); - const width: usize = displayWidth(line_text[a..b]) +| past; + const width: usize = displayWidth(tab, line_text[a..b]) +| past; return if (to_raw >= from_raw) @intCast(width) else -@as(i32, @intCast(width)); } -pub fn lineDisplayEndOffset(line_text: []const u8, from_raw: usize, at_raw: usize) i32 { - const start = lineDisplayOffset(line_text, from_raw, at_raw); +pub fn lineDisplayEndOffset(tab: u16, line_text: []const u8, from_raw: usize, at_raw: usize) i32 { + const start = lineDisplayOffset(tab, line_text, from_raw, at_raw); if (at_raw >= line_text.len) return start; const at = modal.graphemeStart(line_text, at_raw); const end = modal.nextGrapheme(line_text, at); - return start + @as(i32, @intCast(graphemeDisplayWidth(line_text[at..end]))) - 1; + return start + @as(i32, @intCast(graphemeDisplayWidth(tab, line_text[at..end]))) - 1; } pub fn sourceLine(pane: *const Pane, row: i32) []const u8 { @@ -295,9 +295,9 @@ pub fn sourceLine(pane: *const Pane, row: i32) []const u8 { /// width a wrapping body has (a wider one is shown as its source, wrapped); /// else none. Every mapping between a file row's bytes and its cells goes /// through here, so the drawn row, the caret and a click cannot disagree. -pub fn rowPads(pane: *const Pane, row: i32, out: *[Tables.max_pads]Tables.Pad) []const Tables.Pad { +pub fn rowPads(tab: u16, pane: *const Pane, row: i32, out: *[Tables.max_pads]Tables.Pad) []const Tables.Pad { const table = rowTable(pane, row) orelse return &.{}; - return pane.file.?.tables.padsOf(table, @intCast(row), sourceLine(pane, row), out); + return pane.file.?.tables.padsOf(tab, table, @intCast(row), sourceLine(pane, row), out); } /// The table `row` is laid out in, in this pane (`rowPads`). @@ -310,28 +310,28 @@ pub fn rowTable(pane: *const Pane, row: i32) ?*const Tables.Table { return table; } -pub fn displayOffset(pane: *const Pane, row: i32, from_raw: i32, to_raw: i32) i32 { +pub fn displayOffset(tab: u16, pane: *const Pane, row: i32, from_raw: i32, to_raw: i32) i32 { const line_text = sourceLine(pane, row); const from: usize = @intCast(@max(0, from_raw)); const to: usize = @intCast(@max(0, to_raw)); var buf: [Tables.max_pads]Tables.Pad = undefined; - return lineDisplayOffset(line_text, from, to) + Tables.between(rowPads(pane, row, &buf), from, to); + return lineDisplayOffset(tab, line_text, from, to) + Tables.between(rowPads(tab, pane, row, &buf), from, to); } -pub fn displayEndOffset(pane: *const Pane, row: i32, from_raw: i32, at_raw: i32) i32 { +pub fn displayEndOffset(tab: u16, pane: *const Pane, row: i32, from_raw: i32, at_raw: i32) i32 { const line_text = sourceLine(pane, row); const from: usize = @intCast(@max(0, from_raw)); const at: usize = @intCast(@max(0, at_raw)); var buf: [Tables.max_pads]Tables.Pad = undefined; - return lineDisplayEndOffset(line_text, from, at) + Tables.between(rowPads(pane, row, &buf), from, at); + return lineDisplayEndOffset(tab, line_text, from, at) + Tables.between(rowPads(tab, pane, row, &buf), from, at); } -pub fn byteAtRowDisplay(pane: *const Pane, row: i32, from_raw: i32, display_col: i32) i32 { +pub fn byteAtRowDisplay(tab: u16, pane: *const Pane, row: i32, from_raw: i32, display_col: i32) i32 { const line_text = sourceLine(pane, row); var buf: [Tables.max_pads]Tables.Pad = undefined; - const pads = rowPads(pane, row, &buf); - if (pads.len > 0) return @intCast(Tables.byteAt(line_text, pads, @intCast(@max(0, from_raw)), @intCast(@max(0, display_col)))); - return @intCast(byteAtDisplayFrom(line_text, @intCast(@max(0, from_raw)), @intCast(@max(0, display_col)))); + const pads = rowPads(tab, pane, row, &buf); + if (pads.len > 0) return @intCast(Tables.byteAt(tab, line_text, pads, @intCast(@max(0, from_raw)), @intCast(@max(0, display_col)))); + return @intCast(byteAtDisplayFrom(tab, line_text, @intCast(@max(0, from_raw)), @intCast(@max(0, display_col)))); } pub fn gutterWidth(pane: *const Pane) u16 { @@ -351,23 +351,23 @@ pub fn gutterWidth(pane: *const Pane) u16 { /// Convert between rendered cells and UTF-8 byte columns. Tag rows always /// need grapheme conversion; file body rows additionally skip the gutter. -pub fn renderedLineByteCol(pane: *const Pane, row: i32, line_text: []const u8, display_col: usize) usize { - if (row < pane.tag_rows) return rawAtDisplay(line_text, display_col); - if (pane.file == null) return rawAtDisplay(line_text, display_col); +pub fn renderedLineByteCol(tab: u16, pane: *const Pane, row: i32, line_text: []const u8, display_col: usize) usize { + if (row < pane.tag_rows) return rawAtDisplay(tab, line_text, display_col); + if (pane.file == null) return rawAtDisplay(tab, line_text, display_col); const prefix = @min(@as(usize, gutterWidth(pane)), line_text.len); if (display_col <= prefix) return display_col; - return prefix +| rawAtDisplay(line_text[prefix..], display_col - prefix); + return prefix +| rawAtDisplay(tab, line_text[prefix..], display_col - prefix); } -pub fn renderedLineDisplayCol(pane: *const Pane, row: i32, line_text: []const u8, byte_col: usize) usize { - if (row < pane.tag_rows) return rawDisplayCol(line_text, byte_col); - if (pane.file == null) return rawDisplayCol(line_text, byte_col); +pub fn renderedLineDisplayCol(tab: u16, pane: *const Pane, row: i32, line_text: []const u8, byte_col: usize) usize { + if (row < pane.tag_rows) return rawDisplayCol(tab, line_text, byte_col); + if (pane.file == null) return rawDisplayCol(tab, line_text, byte_col); const prefix = @min(@as(usize, gutterWidth(pane)), line_text.len); if (byte_col <= prefix) return byte_col; - return prefix +| rawDisplayCol(line_text[prefix..], byte_col - prefix); + return prefix +| rawDisplayCol(tab, line_text[prefix..], byte_col - prefix); } -fn fitEnd(text: []const u8, start: usize, width: usize) usize { +fn fitEnd(tab: u16, text: []const u8, start: usize, width: usize) usize { var end = start; var used: usize = 0; while (used < width and end < text.len) { @@ -379,7 +379,7 @@ fn fitEnd(text: []const u8, start: usize, width: usize) usize { } while (end < text.len) { const next_end = modal.nextGrapheme(text, end); - const next_used = used +| graphemeDisplayWidth(text[end..next_end]); + const next_used = used +| graphemeDisplayWidth(tab, text[end..next_end]); if (next_used > width) return if (end == start) next_end else end; used = next_used; end = next_end; @@ -1136,9 +1136,9 @@ fn followChain(p: *Pardes, twin: u32) void { if (active) |k| if (v.header == null and chain[k].focus == .body) hop: { const m = chain[k]; const row: usize = @intCast(@max(0, m.body.cur_row)); - if (m.follow_crossed and (row < m.file.?.scroll or row >= pageEnd(m))) { + if (m.follow_crossed and (row < m.file.?.scroll or row >= pageEnd(p.settings.tab, m))) { const j = for (chain[0..n], 0..) |o, i| { - if (row >= o.file.?.scroll and row < pageEnd(o)) break i; + if (row >= o.file.?.scroll and row < pageEnd(p.settings.tab, o)) break i; } else if (row < m.file.?.scroll) 0 else n - 1; if (j == k) break :hop; const to = chain[j]; @@ -1151,7 +1151,7 @@ fn followChain(p: *Pardes, twin: u32) void { m.body.mode = .normal; v.active = ids[j]; to.follow_edges = @as(u2, @intFromBool(j > 0)) | @as(u2, @intFromBool(j + 1 < n)) << 1; - to.ensureCursorVisible(); + to.ensureCursorVisible(p.settings.tab); } }; // The page that moved (the keyboard's first), else the head, sets the @@ -1170,12 +1170,12 @@ fn followChain(p: *Pardes, twin: u32) void { setPageScroll(prev, s); while (s < want) : (s += 1) { setPageScroll(prev, s + 1); - if (pageEnd(prev) <= want) continue; + if (pageEnd(p.settings.tab, prev) <= want) continue; setPageScroll(prev, s); break; } } - for (chain[1..n], 0..) |o, i| setPageScroll(o, pageEnd(chain[i])); + for (chain[1..n], 0..) |o, i| setPageScroll(o, pageEnd(p.settings.tab, chain[i])); // Only the keyboard's page crosses its edges: a dot written to another // scrolls it there, and the chain with it. for (chain[0..n], ids[0..n], 0..) |o, id, i| { @@ -1187,16 +1187,16 @@ fn followChain(p: *Pardes, twin: u32) void { /// The line a page after `pane`'s starts on: the one after its last row's, /// or that line again when the pane wraps it on past its bottom. -fn pageEnd(pane: *Pane) usize { +fn pageEnd(tab: u16, pane: *Pane) usize { const f = &pane.file.?; - geometry(pane); + geometry(tab, pane); if (pane.wrap_n == 0) return f.scroll + pane.rows; const last = (if (pane.body_visible_rows > 0) @min(pane.wrap_n, pane.body_visible_rows) else pane.wrap_n) - 1; const line: usize = @intCast(pane.wrap_line[last]); if (!pane.body_wrapped or line >= nlines(pane.gpa, f)) return line + 1; const text = sourceLine(pane, @intCast(line)); const width = wrapWidth(pane, pane.view.wrap) -| pane.wrap_pad[last]; - return if (fitEnd(text, @intCast(pane.wrap_col[last]), width) < text.len) @max(line, f.scroll + 1) else line + 1; + return if (fitEnd(tab, text, @intCast(pane.wrap_col[last]), width) < text.len) @max(line, f.scroll + 1) else line + 1; } fn setPageScroll(pane: *Pane, line: usize) void { @@ -1283,7 +1283,7 @@ fn restoreName(p: *Pardes, pane: *Pane, f: *State, snap: Text.Place) void { if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); } -pub fn restoreSnap(pane: *Pane, f: *State, snap: Text.Place) void { +pub fn restoreSnap(tab: u16, pane: *Pane, f: *State, snap: Text.Place) void { const n = nlines(pane.gpa, f); const row: usize = @min(@as(usize, @intCast(@max(0, snap.cur_row))), n - 1); const llen = modal.lineSlice(f.content, row).len; @@ -1292,7 +1292,7 @@ pub fn restoreSnap(pane: *Pane, f: *State, snap: Text.Place) void { pane.body.vsel = snap.vsel; pane.body.cur_pinned = true; pane.body.sticky_col = -1; - pane.ensureCursorVisible(); + pane.ensureCursorVisible(tab); } /// An undo step's edge, made before an edit (Text.Journal.mark): the edits @@ -1321,7 +1321,7 @@ pub fn undoStep(p: *Pardes, pane: *Pane, back: bool) error{OutOfMemory}!void { } const to = if (back) s.before else s.after; restoreName(p, pane, f, to); - restoreSnap(pane, f, to); + restoreSnap(p.settings.tab, pane, f, to); } /// Step `at`'s entries turned round in `f`'s text: each one's bytes put @@ -1495,7 +1495,7 @@ pub fn changed(p: *Pardes, id: u8, bytes: []const u8) void { const new = p.gpa.dupe(u8, bytes) catch |err| return p.reportError(id, "reload", err); setContent(p, f, new); f.saved_revision = f.revision; - restoreSnap(pane, f, .{ .cur_row = pane.body.cur_row, .cur_col = pane.body.cur_col, .vsel = pane.body.vsel }); + restoreSnap(p.settings.tab, pane, f, .{ .cur_row = pane.body.cur_row, .cur_col = pane.body.cur_col, .vsel = pane.body.vsel }); } /// re-highlight the visible window of any file whose syntax went stale @@ -1644,11 +1644,11 @@ pub fn wrapWidth(pane: *const Pane, wrap: bool) usize { pub const VisualRow = struct { start: usize, end: usize }; -pub fn visualRow(line: []const u8, col: usize, width: usize) VisualRow { +pub fn visualRow(tab: u16, line: []const u8, col: usize, width: usize) VisualRow { if (width == 0) return .{ .start = 0, .end = line.len }; var start: usize = 0; while (true) { - const end = fitEnd(line, start, width); + const end = fitEnd(tab, line, start, width); if (col < end or end >= line.len) return .{ .start = start, .end = end }; start = end; } @@ -1656,10 +1656,10 @@ pub fn visualRow(line: []const u8, col: usize, width: usize) VisualRow { /// The body's text as it is shown: its geometry's rows, each a line's /// number and its stretch of the line. -pub fn bodyText(arena: std.mem.Allocator, pane: *Pane, f: *State) ![]const u8 { - geometry(pane); +pub fn bodyText(tab: u16, arena: std.mem.Allocator, pane: *Pane, f: *State) ![]const u8 { + geometry(tab, pane); const out = try arena.alloc(u8, pane.geometry_len); - const filled = fillBody(out, pane, f, wrapWidth(pane, pane.view.wrap), false); + const filled = fillBody(tab, out, pane, f, wrapWidth(pane, pane.view.wrap), false); std.debug.assert(filled == out.len); return out; } @@ -1671,7 +1671,7 @@ pub fn bodyText(arena: std.mem.Allocator, pane: *Pane, f: *State) ![]const u8 { /// reads it: so a core that never draws has the geometry of one that does /// (docs/next-daemon.md). What it reads of the session is the pane's `view`, /// which each step sets. -pub fn geometry(pane: *Pane) void { +pub fn geometry(tab: u16, pane: *Pane) void { const f = if (pane.file) |*file| file else return; const key = geometryKey(pane, f); if (pane.geometry_key == key) return; @@ -1679,7 +1679,7 @@ pub fn geometry(pane: *Pane) void { pane.body_rows = 0; pane.body_visible_rows = 0; pane.context_row_limit = null; - pane.geometry_len = mapRows(pane, f); + pane.geometry_len = mapRows(tab, pane, f); // A body with context rows is a layer taller than the grid's rows, its // context rows at the tagline's height (body_layer.joinBody). const v = pane.view; @@ -1693,17 +1693,17 @@ pub fn geometry(pane: *Pane) void { const limit: u16 = @intCast(@min(pane.context_rows, (body_pixels -| bh) / th)); pane.context_row_limit = limit; pane.body_visible_rows = @intCast(@min(logical_rows, limit + @max(1, (body_pixels -| @as(usize, limit) * th) / bh))); - pane.geometry_len = mapRows(pane, f); + pane.geometry_len = mapRows(tab, pane, f); } /// One walk of the rows the body shows, recording the wrap map: the bytes /// its text takes. -fn mapRows(pane: *Pane, f: *State) usize { +fn mapRows(tab: u16, pane: *Pane, f: *State) usize { const width = wrapWidth(pane, pane.view.wrap); pane.body_wrapped = width > 0; - f.tables.ensure(pane.gpa, f); + f.tables.ensure(tab, pane.gpa, f); prepareContextRows(pane, f); - return fillBody(null, pane, f, width, true); + return fillBody(tab, null, pane, f, width, true); } /// Everything the geometry is made of, hashed: the text (its revision and @@ -1730,7 +1730,7 @@ fn geometryKey(pane: *const Pane, f: *const State) u64 { /// Run the file-body row walk. With no destination it is the exact sizing /// pass; with one it fills that allocation and records the wrapping map. -fn fillBody(dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) usize { +fn fillBody(tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) usize { if (record_wrap) pane.wrap_n = 0; const prefix_width = gutterWidth(pane); const total = nlines(pane.gpa, f); @@ -1752,10 +1752,10 @@ fn fillBody(dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) locations.treeContinuation(text, &guide_buffer, width - 1) else ""; - const pad = displayWidth(guide); + const pad = displayWidth(tab, guide); // Headers use one screen row per source row, preserving signatures // without allowing a long ancestor to consume the whole viewport. - const end = if (width == 0 or context) text.len else fitEnd(text, at, width - pad); + const end = if (width == 0 or context) text.len else fitEnd(tab, text, at, width - pad); const cut = if (pane.hscroll > 0 and width == 0) modal.graphemeStart(text, @min(@as(usize, @intCast(pane.hscroll)), text.len)) else @@ -1788,7 +1788,7 @@ fn fillBody(dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) // drawn as the column functions above measure it. var pad_buf: [Tables.max_pads]Tables.Pad = undefined; var from = cut; - for (rowPads(pane, @intCast(row), &pad_buf)) |table_pad| { + for (rowPads(tab, pane, @intCast(row), &pad_buf)) |table_pad| { if (table_pad.at <= cut) continue; if (table_pad.at > end) break; if (dst) |out| @memcpy(out[written..][0 .. table_pad.at - from], text[from..table_pad.at]); @@ -1866,7 +1866,7 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. line.len; } hs = modal.graphemeStart(line, @min(hs, line.len)); - const row_index: usize = @intCast(@max(0, pane.wrapAt(vr).line)); + const row_index: usize = @intCast(@max(0, pane.wrapAt(p.settings.tab, vr).line)); const metadata: ?locations.Row = if (row_index < f.location_rows.len) f.location_rows[row_index] else null; const decoration = Output.decorateRow(f.output, line, metadata); const chrome: ?*const pardes.ChromeTheme = if (decoration.plain()) null else p.bodyChrome(); @@ -1896,7 +1896,7 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. } var screen_c: usize = pad; var table_buf: [Tables.max_pads]Tables.Pad = undefined; - const table_pads = rowPads(pane, @intCast(row_index), &table_buf); + const table_pads = rowPads(p.settings.tab, pane, @intCast(row_index), &table_buf); var table_at: usize = 0; while (hs + c < limit and prefix_width + screen_c < tw) { while (table_at < table_pads.len and table_pads[table_at].at < hs + c) table_at += 1; @@ -1906,7 +1906,7 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. if (prefix_width + screen_c >= tw) break; } const grapheme_end = @min(limit, modal.nextGrapheme(line, hs + c)); - const cells = graphemeDisplayWidth(line[hs + c .. grapheme_end]); + const cells = graphemeDisplayWidth(p.settings.tab, line[hs + c .. grapheme_end]); const idx = base + hs + c; // Each painter (the syntax colour, a diff's emphasis ground, a // result's emphasis, a +Pager's colours) loops over the cells @@ -1997,15 +1997,15 @@ pub fn paintWordSelection( const body_y = p.bodyTop(pane, r); var vr: i32 = 0; while (vr + @as(i32, pane.tag_rows) < @as(i32, r.h)) : (vr += 1) { - const here = pane.wrapAt(vr); + const here = pane.wrapAt(p.settings.tab, vr); if (here.line != row) continue; var hi = word_hi; - const next = pane.wrapAt(vr + 1); + const next = pane.wrapAt(p.settings.tab, vr + 1); if (next.line == row) hi = @min(hi, next.at); const lo = @max(word_lo, here.at); if (hi <= lo) continue; - const c0 = @as(i32, prefix_width) + here.pad + displayOffset(pane, row, here.at, lo); - const c1 = @as(i32, prefix_width) + here.pad + displayEndOffset(pane, row, here.at, hi - 1); + const c0 = @as(i32, prefix_width) + here.pad + displayOffset(p.settings.tab, pane, row, here.at, lo); + const c1 = @as(i32, prefix_width) + here.pad + displayEndOffset(p.settings.tab, pane, row, here.at, hi - 1); const col = @max(@as(i32, prefix_width), c0); const end = @min(c1 + 1, @as(i32, tw)); if (col < end) s.tint(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(vr)), @intCast(end - col), bg, null); @@ -2013,12 +2013,12 @@ pub fn paintWordSelection( } test "an invalid byte in a grapheme is one cell, and never reaches vaxis's width" { - try std.testing.expectEqual(@as(usize, 2), graphemeDisplayWidth("\xeee\xcc\x81")); - try std.testing.expectEqual(@as(usize, 3), graphemeDisplayWidth("\xee\xffe")); - try std.testing.expectEqual(@as(usize, 3), graphemeDisplayWidth("\u{4e16}\x80")); + try std.testing.expectEqual(@as(usize, 2), graphemeDisplayWidth(config.tab_width, "\xeee\xcc\x81")); + try std.testing.expectEqual(@as(usize, 3), graphemeDisplayWidth(config.tab_width, "\xee\xffe")); + try std.testing.expectEqual(@as(usize, 3), graphemeDisplayWidth(config.tab_width, "\u{4e16}\x80")); // The whole path the 9P fuzzer took: a body holding it, fitted to a width. const text = "\xeee\xcc\x81"; - try std.testing.expectEqual(@as(usize, 4), fitEnd(text, 0, 10)); + try std.testing.expectEqual(@as(usize, 4), fitEnd(config.tab_width, text, 0, 10)); } test "indexed source rows match uncached scans across content changes" { @@ -2054,7 +2054,7 @@ test "indexed source rows match uncached scans across content changes" { test "the ASCII arm of graphemeDisplayWidth matches the gwidth it skips" { const ref = struct { fn width(grapheme: []const u8) usize { - if (std.mem.eql(u8, grapheme, "\t")) return config.tab_now; + if (std.mem.eql(u8, grapheme, "\t")) return config.tab_width; return @max(1, @as(usize, vaxis.gwidth.gwidth(grapheme, .unicode))); } }.width; @@ -2063,15 +2063,15 @@ test "the ASCII arm of graphemeDisplayWidth matches the gwidth it skips" { var b: u8 = 0; while (b < 0x80) : (b += 1) { one[0] = b; - try std.testing.expectEqual(ref(one[0..1]), graphemeDisplayWidth(one[0..1])); + try std.testing.expectEqual(ref(one[0..1]), graphemeDisplayWidth(config.tab_width, one[0..1])); } for ([_][]const u8{ "e\u{301}", "a\u{903}", "1\u{fe0f}\u{20e3}", "\u{4e16}", "\u{1f642}", "\u{1f1e6}\u{1f1e7}", "\xff", - }) |g| try std.testing.expectEqual(ref(g), graphemeDisplayWidth(g)); + }) |g| try std.testing.expectEqual(ref(g), graphemeDisplayWidth(config.tab_width, g)); // Two invalid bytes are two cells, as surface.zig draws them, where // vaxis's own count gives the pair one. - try std.testing.expectEqual(@as(usize, 2), graphemeDisplayWidth("\xe4\xb8")); + try std.testing.expectEqual(@as(usize, 2), graphemeDisplayWidth(config.tab_width, "\xe4\xb8")); } test "the ASCII run in fitEnd survives an exhaustive byte sweep" { @@ -2081,7 +2081,7 @@ test "the ASCII run in fitEnd survives an exhaustive byte sweep" { var used: usize = 0; while (end < text.len) { const next_end = modal.nextGrapheme(text, end); - const next_used = used +| graphemeDisplayWidth(text[end..next_end]); + const next_used = used +| graphemeDisplayWidth(config.tab_width, text[end..next_end]); if (next_used > width) return if (end == start) next_end else end; used = next_used; end = next_end; @@ -2115,7 +2115,7 @@ test "the ASCII run in fitEnd survives an exhaustive byte sweep" { while (start <= text.len) : (start += 1) { std.testing.expectEqual( reference(text, start, width), - fitEnd(text, start, width), + fitEnd(config.tab_width, text, start, width), ) catch |e| { std.debug.print("fitEnd({any}, {d}, {d})\n", .{ text, start, width }); return e; @@ -2134,7 +2134,7 @@ test "the ASCII run in fitEnd cuts where the grapheme walk would" { var used: usize = 0; while (end < text.len) { const next_end = modal.nextGrapheme(text, end); - const next_used = used +| graphemeDisplayWidth(text[end..next_end]); + const next_used = used +| graphemeDisplayWidth(config.tab_width, text[end..next_end]); if (next_used > width) return if (end == start) next_end else end; used = next_used; end = next_end; @@ -2166,7 +2166,7 @@ test "the ASCII run in fitEnd cuts where the grapheme walk would" { while (start <= text.len) : (start += 1) { try std.testing.expectEqual( reference(text, start, width), - fitEnd(text, start, width), + fitEnd(config.tab_width, text, start, width), ); } } @@ -2309,17 +2309,17 @@ test "a caret deep in a long line scrolls the view sideways to it, measured from _ = try p.render(arena.allocator()); // Right, far: the caret ends a margin in from the right edge. pane.body.cur_col = 400_000; - pane.ensureCursorVisible(); + pane.ensureCursorVisible(config.tab_width); const w: i32 = @as(i32, pane.cols) - @as(i32, gutterWidth(pane)); const hmargin: i32 = @min(config.scroll_off, @divTrunc(w - 1, 2)); try std.testing.expectEqual(@as(i32, 400_000 - (w - 1 - hmargin)), pane.hscroll); // Back left of the view: a margin in from the left edge. pane.body.cur_col = 100_000; - pane.ensureCursorVisible(); + pane.ensureCursorVisible(config.tab_width); try std.testing.expectEqual(@as(i32, 100_000 - hmargin), pane.hscroll); // At the start: none. pane.body.cur_col = 1; - pane.ensureCursorVisible(); + pane.ensureCursorVisible(config.tab_width); try std.testing.expectEqual(@as(i32, 0), pane.hscroll); } diff --git a/core/Jump.zig b/core/Jump.zig index b958b30b..3b8c8d01 100644 --- a/core/Jump.zig +++ b/core/Jump.zig @@ -374,7 +374,7 @@ test "jump history skips an entry whose pane slot or serial is gone, leaving the p.view().jumps.n = 2; p.view().jumps.cur = 1; p.view().jumps.list[1] = .{ .pane = 0, .serial = pane.serial, .line = 1, .col = 1 }; - pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true); + pane.body.setRange(p.settings.tab, pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true); const selected = pane.body.primaryRange(pane.file.?.content, 0); for ([_]Loc{ .{ .pane = 15, .serial = pane.serial, .line = 1, .col = 1 }, diff --git a/core/Kind.zig b/core/Kind.zig index a624d7c6..9844369d 100644 --- a/core/Kind.zig +++ b/core/Kind.zig @@ -137,7 +137,7 @@ pub const Slot = struct { // jobs' inputs, its file's hash, a placeholder's record), and what // a frame makes (the thumb, the pointer, whether one was drawn: a // view's, never a step's). - .local = .{ "ops", "st", "gpa", "arena", "plain", "file", "opened", "reloads", "jobs", "record", "thumb_at", "thumb_span", "pointer", "painted", "over", "used" }, + .local = .{ "ops", "st", "gpa", "arena", "plain", "file", "opened", "reloads", "jobs", "record", "thumb_at", "thumb_span", "pointer", "painted", "over", "used", "draws" }, }; /// Its kind's code here; null in a placeholder (`live` false: its kind /// not in the registry, its record kept for the day it comes) or a @@ -199,6 +199,11 @@ pub const Slot = struct { /// whether a frame was painted since its last tick. pointer: u8 = 0, painted: bool = false, + /// The last of its draws' tokens (api.draw), each its own process's: a + /// draw is a frame's, and how many frames each process paints differs, + /// so it is in no digest; the copy holds it with the slot. A kind + /// keeping one in its state (PA_PLAIN) is caught at that call's digest. + draws: u32 = 0, /// Each view's facts (a hash of its pa_view) as `view` was last told /// them, 0 for none: a change tells it again. views: [views.max]u64 = @splat(0), @@ -299,7 +304,7 @@ pub fn reopen(p: ?*Pardes, id: usize, s: *Slot, bytes: ?[]const u8) bool { const prev = cl.begin("open"); if (p) |core| if (core.kinds.byName(s.nameOf())) |k| { // Its code: its library loaded at the first pane of its kind. - if (s.ops == null) s.ops = Addon.need(&core.kinds, k, &cl.refused); + if (s.ops == null) s.ops = Addon.need(&core.kinds, k, &cl.refused, core.opts.distrusted); // Its block made afresh by this open. if (core.kinds.kinds[k].caps.plain) { if (s.plain) |b| if (b.len > 0) s.gpa.free(b); @@ -980,7 +985,7 @@ const Call = struct { // Run here, it came out otherwise than the session's: it broke its // promise (PA_PLAIN), and the client joins again without it. if (cl.slot.ops != null and cl.slot.plain != null and tape.replaying() and o.state != state) { - pardes.Addon.distrust(cl.slot.nameOf()); + if (cl.p) |p| if (p.opts.distrusted) |d| d.add(cl.slot.nameOf()); var why: Buf(160) = .{}; tape.diverged(why.print("addon {s}: its state after {s} is not the session's (it breaks PA_PLAIN): the session's alone now", .{ cl.slot.nameOf(), cl.name })); } @@ -1215,8 +1220,8 @@ pub const api: c.pa_api = .{ heap.free(copy); return 0; }; - draw_tokens = (draw_tokens +% 1) & ~c.PA_DRAWN; - const token = c.PA_DRAWN | draw_tokens; + cl.slot.draws = (cl.slot.draws +% 1) & ~c.PA_DRAWN; + const token = c.PA_DRAWN | cl.slot.draws; j.* = .{ .gpa = heap, .pane = @intCast(cl.id), .serial = pane.serial, .token = token, .gen = cl.slot.gen, .ops = ops, .in = copy, .arena = .init(heap), .draw = p }; Addon.holdJob(ops, true); if (drawer) |d| if (d.go(d.ctx, j)) return token; @@ -1243,7 +1248,6 @@ pub const api: c.pa_api = .{ /// which post each back to its loop to land (host_io.KindJob.land); false, /// or none (a test's core), and it runs here at once. pub var drawer: ?struct { ctx: ?*anyopaque, go: *const fn (ctx: ?*anyopaque, j: *host_io.KindJob) bool } = null; -var draw_tokens: u32 = 0; /// Draws done, each kept for its pane's next paint (the loop's alone). var ready: std.ArrayListUnmanaged(*host_io.KindJob) = .empty; diff --git a/core/Messages.zig b/core/Messages.zig index 4080ff61..414d72c6 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -466,7 +466,7 @@ pub fn collectNotices(p: *Pardes, pane: *Pane, r: Rect, id: usize) void { const tw = r.w -| config.GUTTER; var leader_buf: [16]u8 = undefined; for (0..pane.notices.len) |i| { - const chip = panes.File.displayWidth(noticeText(p, pane, i, &leader_buf)) + 2; + const chip = panes.File.displayWidth(p.settings.tab, noticeText(p, pane, i, &leader_buf)) + 2; pane.notices.left[i] = if (tw == 0) std.math.maxInt(u16) else tx + tw - @as(u16, @intCast(@min(chip, tw))); } } diff --git a/core/Output.zig b/core/Output.zig index 4284faf3..600ab085 100644 --- a/core/Output.zig +++ b/core/Output.zig @@ -389,7 +389,7 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] if (!std.meta.eql(output.from, from)) continue; if (by_arg and !std.mem.eql(u8, output.arg(), arg)) continue; if (!std.mem.eql(u8, std.Io.Dir.path.dirname(rf.path) orelse "", dir)) continue; - if (!locations.sameInput(content, rf.content, rf.location_rows, p.locations_config.layout)) continue; + if (!locations.sameInput(p.settings.tab, content, rf.content, rf.location_rows, p.locations_config.layout)) continue; try setArg(output, arg); p.gpa.free(content); p.fs.refilled = rp.serial; @@ -1018,10 +1018,10 @@ test "stacked empty previews distinguish separators from trailing newlines" { .{ .kind = .match, .path = &path, .at = .{ .line = 1, .col = 1 }, .location_end = 7, .code_start = 7 }, .{ .kind = .preview, .path = &path, .at = .{ .line = 1, .col = 1 }, .location_end = 0, .code_start = 0 }, }; - try std.testing.expect(locations.sameInput("x.c:1:1 ", "x.c:1:1\n", &rows, .stacked)); - try std.testing.expect(locations.sameInput("x.c:1:1 \n", "x.c:1:1\n\n", &rows, .stacked)); - try std.testing.expect(!locations.sameInput("x.c:1:1 ", "x.c:1:1\n\n", &rows, .stacked)); - try std.testing.expect(!locations.sameInput("x.c:1:1 \n", "x.c:1:1\n", &rows, .stacked)); + try std.testing.expect(locations.sameInput(config.tab_width, "x.c:1:1 ", "x.c:1:1\n", &rows, .stacked)); + try std.testing.expect(locations.sameInput(config.tab_width, "x.c:1:1 \n", "x.c:1:1\n\n", &rows, .stacked)); + try std.testing.expect(!locations.sameInput(config.tab_width, "x.c:1:1 ", "x.c:1:1\n\n", &rows, .stacked)); + try std.testing.expect(!locations.sameInput(config.tab_width, "x.c:1:1 \n", "x.c:1:1\n", &rows, .stacked)); } test "two words looked for in a terminal share the directory's one +Search" { diff --git a/core/Pipe.zig b/core/Pipe.zig index 59613222..85329971 100644 --- a/core/Pipe.zig +++ b/core/Pipe.zig @@ -281,7 +281,7 @@ pub fn pipeResponse( m += 1; } if (m == 0) return; - return t.setRanges(content, kept[0..m], &.{}, pri orelse m - 1, wait.explicit); + return t.setRanges(p.settings.tab, content, kept[0..m], &.{}, pri orelse m - 1, wait.explicit); } // Each range's cut with its output in place, in order: one splice of @@ -320,9 +320,9 @@ pub fn pipeResponse( }; edit.setEditText(p.editor(), t, replacement) catch |err| return p.reportError(wait.pane, "pipe", err); const now = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(wait.pane, "pipe", err); - t.setRanges(now, new_ranges[0..n], &.{}, wait.primary, wait.explicit); + t.setRanges(p.settings.tab, now, new_ranges[0..n], &.{}, wait.primary, wait.explicit); t.select = false; - t.show(); + t.show(p.settings.tab); } fn nextPipeEffect(p: *Pardes) ?u32 { @@ -402,7 +402,7 @@ test "$ keeps the selections the command exits 0 on, and a real shell gives that .{ .anchor = 3, .head = 5 }, .{ .anchor = 6, .head = 8 }, }; - pane.body.setRanges(pane.file.?.content, &ranges, &.{}, 1, true); + pane.body.setRanges(config.tab_width, pane.file.?.content, &ranges, &.{}, 1, true); p.update(.{ .key = .{ .cp = '$' } }); try std.testing.expectEqualStrings(config.pipe_marker_keep, pane.promptText().?); p.update(.{ .key = .{ .cp = 'g', .text = "grep -v b" } }); @@ -438,7 +438,7 @@ test "selection pipe replaces all ranges atomically and undo restores them" { .{ .anchor = 0, .head = 2 }, .{ .anchor = 6, .head = 8 }, }; - pane.body.setRanges(pane.file.?.content, &ranges, &.{}, 0, true); + pane.body.setRanges(config.tab_width, pane.file.?.content, &ranges, &.{}, 0, true); p.update(.{ .key = .{ .cp = '|' } }); p.update(.{ .key = .{ .cp = 'c', .text = "cat" } }); @@ -472,7 +472,7 @@ test "a pipe's output past its cap leaves the text as it was, and says so" { while (p.nextEffect()) |_| {} const pane = try p.setTestFile("aa bb cc\n"); const ranges = [_]modal.Selection{ .{ .anchor = 0, .head = 2 }, .{ .anchor = 6, .head = 8 } }; - pane.body.setRanges(pane.file.?.content, &ranges, &.{}, 1, true); + pane.body.setRanges(config.tab_width, pane.file.?.content, &ranges, &.{}, 1, true); p.update(.{ .key = .{ .cp = '|' } }); p.update(.{ .key = .{ .cp = 'c', .text = "cat" } }); p.update(.{ .key = .{ .cp = Key.enter } }); @@ -510,7 +510,7 @@ test "the four shell behaviours put their output where helix puts it" { defer p.deinit(); while (p.nextEffect()) |_| {} const pane = try p.setTestFile("aa bb cc\n"); - pane.body.setRanges(pane.file.?.content, &.{.{ .anchor = 3, .head = 5 }}, &.{}, 0, true); + pane.body.setRanges(config.tab_width, pane.file.?.content, &.{.{ .anchor = 3, .head = 5 }}, &.{}, 0, true); p.update(.{ .key = case.key }); for ("cmd") |c| p.update(.{ .key = .{ .cp = c, .text = &.{c} } }); @@ -531,7 +531,7 @@ test "a command with no stdin runs once and every cursor gets that one answer" { .{ .anchor = 0, .head = 2 }, .{ .anchor = 6, .head = 8 }, }; - pane.body.setRanges(pane.file.?.content, &ranges, &.{}, 0, true); + pane.body.setRanges(config.tab_width, pane.file.?.content, &ranges, &.{}, 0, true); p.update(.{ .key = .{ .cp = '!' } }); // insert-output: no stdin for ("date") |c| p.update(.{ .key = .{ .cp = c, .text = &.{c} } }); diff --git a/core/Places.zig b/core/Places.zig index 9b8754b9..1416dbd3 100644 --- a/core/Places.zig +++ b/core/Places.zig @@ -433,7 +433,7 @@ pub fn fill(set: *Places, p: *Pardes, pane: *Pane, bytes: usize, steps: u64) voi } if (set.fold and (set.hay_revision != f.revision or set.hay.len != f.content.len)) if (!set.freshHay(gpa, f)) return set.clear(gpa); - if (set.re == null) return set.settleSeek(pane); + if (set.re == null) return set.settleSeek(p.settings.tab, pane); const re = &set.re.?; const hay: []const u8 = if (set.fold) set.hay else f.content; for (re.branches) |*b| b.re.steps = @max(1, steps / re.branches.len); @@ -506,12 +506,12 @@ pub fn fill(set: *Places, p: *Pardes, pane: *Pane, bytes: usize, steps: u64) voi set.gen +%= 1; set.hits_gen +%= 1; } - set.settleSeek(pane); + set.settleSeek(p.settings.tab, pane); } /// The place at or after `seek` becomes current, once all the text /// between them has been searched (never a false "next" across a gap). -fn settleSeek(set: *Places, pane: *Pane) void { +fn settleSeek(set: *Places, tab: u16, pane: *Pane) void { const seek = set.seek orelse return; const hits = set.hits.items; const i = firstFrom(hits, seek); @@ -525,10 +525,10 @@ fn settleSeek(set: *Places, pane: *Pane) void { set.seek = null; set.gen +%= 1; if (!set.seek_moves) return; - if (set.current) |c| return set.goTo(pane, c, false); + if (set.current) |c| return set.goTo(tab, pane, c, false); // Nothing matches: the body as it was before the query, as helix // leaves it. - set.restore(pane); + set.restore(tab, pane); } /// The places have more to do on a frame of their own: places still to @@ -542,7 +542,7 @@ pub fn busy(set: *const Places, pane: *const Pane) bool { /// Make place `i` current: the primary selection on it (a new one beside /// the others in select mode, `add`), the view on it, centred when it was /// off it. -pub fn goTo(set: *Places, pane: *Pane, i: usize, add: bool) void { +pub fn goTo(set: *Places, tab: u16, pane: *Pane, i: usize, add: bool) void { const f = if (pane.file) |*file| file else return; if (i >= set.hits.items.len) return; const t = &pane.body; @@ -557,17 +557,17 @@ pub fn goTo(set: *Places, pane: *Pane, i: usize, add: bool) void { .{ .anchor = h.start, .head = h.end }; if (add and got.n < ranges.len) { ranges[got.n] = next; - t.setRanges(text, ranges[0 .. got.n + 1], &.{}, got.n, true); + t.setRanges(tab, text, ranges[0 .. got.n + 1], &.{}, got.n, true); } else { ranges[got.pri] = next; - t.setRanges(text, ranges[0..got.n], &.{}, got.pri, true); + t.setRanges(tab, text, ranges[0..got.n], &.{}, got.pri, true); } set.current = i; set.gen +%= 1; const off = pane.scroll(); if (t.cur_row < off or t.cur_row >= off + @as(i32, pane.rows)) pane.scrollBy(t.cur_row - off - @divTrunc(@as(i32, pane.rows), 2)); - t.show(); + t.show(tab); } /// n and N (and Ctrl-n, Ctrl-p on a query's line): the next place after @@ -596,7 +596,7 @@ pub fn step(set: *Places, p: *Pardes, pane: *Pane, forward: bool, count: u32, ad while (i > 0 and hits[i - 1].end > from) i -= 1; i = if (i == 0) hits.len - 1 else i - 1; } - set.goTo(pane, i, add); + set.goTo(p.settings.tab, pane, i, add); } } @@ -629,14 +629,14 @@ pub fn remember(set: *Places, p: *Pardes, pane: *Pane) void { } /// The body as `remember` kept it: its selections and its view. -pub fn restore(set: *Places, pane: *Pane) void { +pub fn restore(set: *Places, tab: u16, pane: *Pane) void { const f = if (pane.file) |*file| file else return; if (set.snap.len == 0) return; for (set.snap) |*r| { r.anchor = @min(r.anchor, f.content.len); r.head = @min(r.head, f.content.len); } - pane.body.setRanges(f.content, set.snap, &.{}, set.snap_pri, set.snap_expl); + pane.body.setRanges(tab, f.content, set.snap, &.{}, set.snap_pri, set.snap_expl); f.scroll = set.snap_scroll; f.syntax_dirty = true; pane.hscroll = set.snap_hscroll; @@ -672,7 +672,7 @@ pub fn paint(set: *Places, p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, var last_line: i32 = -1; var vr: i32 = 0; while (vr < body_h) : (vr += 1) { - const line = pane.wrapAt(vr).line; + const line = pane.wrapAt(p.settings.tab, vr).line; if (line == last_line or line < 0) continue; if (line >= nlines) break; last_line = line; diff --git a/core/Query.zig b/core/Query.zig index 870f630a..615919c1 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -406,7 +406,7 @@ fn clearPlaces(p: *Pardes, serial: u32, owner_id: ?usize) void { for (p.panes, 0..) |slot, i| { const tp = slot orelse continue; if (tp.places.from != serial) continue; - if (owner_id != null and owner_id.? == i) tp.places.restore(tp); + if (owner_id != null and owner_id.? == i) tp.places.restore(p.settings.tab, tp); tp.places.clear(p.gpa); } } @@ -593,7 +593,7 @@ fn produce(p: *Pardes, id: usize, tick: bool, keyed: bool) void { if (changed) { if (a.pat.len == 0) { if (set.from == rp.serial) set.clear(p.gpa); - set.restore(owner); + set.restore(p.settings.tab, owner); } else set.search(p, owner, .typed, rp.serial, a.pat, false, set.origin(owner), p.view().active == id); } // The owner edited: its places shifted at once; the rows follow @@ -1428,7 +1428,7 @@ fn makeListRows(p: *Pardes, id: usize, pat: []const u8) !void { }; if (next == null and hits.len > 0) next = 0; if (next) |hi| { - owner.places.goTo(owner, hi, false); + owner.places.goTo(p.settings.tab, owner, hi, false); for (q.items.items, 0..) |it, i| if (it.kind == .hit and i + 1 < rp.file.?.location_rows.len) { const meta = rp.file.?.location_rows[i + 1]; if (!std.mem.eql(u8, meta.path, owner_path)) continue; @@ -1586,7 +1586,7 @@ fn showTarget(p: *Pardes, id: usize) void { const tid = p.paneBySerial(it.serial) orelse return; const tp = p.panes[tid].?; if (tp.places.snap.len == 0) tp.places.remember(p, tp); - if (placeOnLine(p, tp, meta.at.line)) |hi| tp.places.goTo(tp, hi, false); + if (placeOnLine(p, tp, meta.at.line)) |hi| tp.places.goTo(p.settings.tab, tp, hi, false); return; } if (q.source == .symbols) { @@ -1621,7 +1621,7 @@ fn selectPlace(p: *Pardes, tp: *Pane, serial: u32, at: look.Spot) bool { const ls = File.lineStart(p.gpa, f, at.line - 1); const i = Places.firstFrom(set.hits.items, ls + (at.col -| 1)); if (i >= set.hits.items.len or (at.line < File.nlines(p.gpa, f) and set.hits.items[i].start >= File.lineStart(p.gpa, f, at.line))) return false; - set.goTo(tp, i, false); + set.goTo(p.settings.tab, tp, i, false); return true; } @@ -1876,7 +1876,7 @@ pub fn cancel(p: *Pardes, id: usize) void { const owner_id = p.paneBySerial(q.owner); for (p.panes) |slot| if (slot) |tp| { if (tp.places.from != rp.serial and tp.serial != q.owner) continue; - tp.places.restore(tp); + tp.places.restore(p.settings.tab, tp); tp.places.forget(p.gpa); if (tp.places.from == rp.serial) tp.places.clear(p.gpa); }; @@ -2074,7 +2074,7 @@ pub fn paintMark(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u const col = File.gutterWidth(pane); var row: i32 = 0; while (row < body_h) : (row += 1) { - if (pane.wrapAt(row).line != @as(i32, @intCast(c + 1)) or col >= tw) continue; + if (pane.wrapAt(p.settings.tab, row).line != @as(i32, @intCast(c + 1)) or col >= tw) continue; s.tint(tx + col, p.bodyTop(pane, r) + @as(u16, @intCast(row)), tw - col, mark, null); } } @@ -2091,7 +2091,7 @@ pub fn paint(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u16) var vr: i32 = 0; var last: i32 = -1; while (vr < body_h) : (vr += 1) { - const row = pane.wrapAt(vr).line; + const row = pane.wrapAt(p.settings.tab, vr).line; if (row == last or row < 1) continue; last = row; const i: usize = @intCast(row - 1); diff --git a/core/Tables.zig b/core/Tables.zig index 0ec69186..dc667b7c 100644 --- a/core/Tables.zig +++ b/core/Tables.zig @@ -134,7 +134,7 @@ pub fn find(t: *const Tables, line: usize) ?*const Table { /// as it is). After one edit (File.State.splice) the tables it did not /// touch shift and only the block around it is read again (`reflow`): a /// keystroke costs its table, not the file. -pub fn ensure(t: *Tables, gpa: std.mem.Allocator, f: *File.State) void { +pub fn ensure(t: *Tables, tab: u16, gpa: std.mem.Allocator, f: *File.State) void { if (t.current(f)) return; defer { t.revision = f.revision; @@ -159,20 +159,20 @@ pub fn ensure(t: *Tables, gpa: std.mem.Allocator, f: *File.State) void { // read: it goes on. if (lineHolding(starts, f.splice.head) >= r.n) { t.lines = starts.len; - t.go(gpa, f.content, 0, first_lines); + t.go(tab, gpa, f.content, 0, first_lines); return; } - } else if (t.reflow(gpa, f)) |_| return else |_| {} + } else if (t.reflow(tab, gpa, f)) |_| return else |_| {} } t.begin(starts.len); - t.go(gpa, f.content, 0, first_lines); + t.go(tab, gpa, f.content, 0, first_lines); } /// A frame's more of a reading under way: on the session's tick, so a core /// that draws reads exactly as far as one that does not. -pub fn step(t: *Tables, gpa: std.mem.Allocator, f: *File.State) void { - t.ensure(gpa, f); - if (t.pending != null) t.go(gpa, f.content, frame_ns, std.math.maxInt(u32)); +pub fn step(t: *Tables, tab: u16, gpa: std.mem.Allocator, f: *File.State) void { + t.ensure(tab, gpa, f); + if (t.pending != null) t.go(tab, gpa, f.content, frame_ns, std.math.maxInt(u32)); } /// Whether a reading of the text is still under way (Pardes.nextWake). @@ -194,9 +194,9 @@ fn begin(t: *Tables, lines: usize) void { /// Read on for about `budget_ns` (0: no clock) or `max_lines`, whichever /// ends first. On no memory there are no tables (the text is shown as it is). -fn go(t: *Tables, gpa: std.mem.Allocator, content: []const u8, budget_ns: u64, max_lines: u32) void { +fn go(t: *Tables, tab: u16, gpa: std.mem.Allocator, content: []const u8, budget_ns: u64, max_lines: u32) void { var at = t.pending orelse return; - const done = t.scanFrom(gpa, content, &at, std.math.maxInt(u32), true, budget_ns, max_lines) catch { + const done = t.scanFrom(tab, gpa, content, &at, std.math.maxInt(u32), true, budget_ns, max_lines) catch { t.list.clearRetainingCapacity(); t.pending = null; return; @@ -227,7 +227,7 @@ fn lineHolding(starts: []const usize, at: usize) usize { /// lines it added), the block around it read again. error.Whole when the /// edit could change what a line far from it is (a fence line in it), or /// the block is unbounded. -fn reflow(t: *Tables, gpa: std.mem.Allocator, f: *File.State) !void { +fn reflow(t: *Tables, tab: u16, gpa: std.mem.Allocator, f: *File.State) !void { const content = f.content; const starts = try File.lineIndex(gpa, f); const sp = f.splice; @@ -300,7 +300,7 @@ fn reflow(t: *Tables, gpa: std.mem.Allocator, f: *File.State) !void { const prev_blank = r0 == 0 or blank(prev) or fenceOf(prev) != null or std.mem.startsWith(u8, prev[@min(indentOf(prev), prev.len)..], "#"); const head = lineOf(content, starts, r0); var at: Resume = .{ .at = head.start, .n = head.n, .fence = null, .prev_blank = prev_blank }; - _ = try t.scanFrom(gpa, content, &at, @intCast(r1), false, 0, std.math.maxInt(u32)); + _ = try t.scanFrom(tab, gpa, content, &at, @intCast(r1), false, 0, std.math.maxInt(u32)); const fresh = try gpa.dupe(Table, t.list.items[before..]); defer gpa.free(fresh); t.list.shrinkRetainingCapacity(before); @@ -492,19 +492,19 @@ fn delimiterCells(text: []const u8, out: *[max_cols]Align) ?usize { } /// The display width of a cell's bytes; ASCII is a cell a byte. -fn widthOf(text: []const u8) usize { - for (text) |b| if (b < 0x20 or b >= 0x7f) return File.displayWidth(text); +fn widthOf(tab: u16, text: []const u8) usize { + for (text) |b| if (b < 0x20 or b >= 0x7f) return File.displayWidth(tab, text); return text.len; } /// Find the tables of `content`, in place of the ones there were. -pub fn scan(t: *Tables, gpa: std.mem.Allocator, content: []const u8) !void { +pub fn scan(t: *Tables, tab: u16, gpa: std.mem.Allocator, content: []const u8) !void { t.list.clearRetainingCapacity(); t.widths.clearRetainingCapacity(); t.aligns.clearRetainingCapacity(); t.begin(std.mem.count(u8, content, "\n") + 1); var at = t.pending.?; - _ = try t.scanFrom(gpa, content, &at, std.math.maxInt(u32), true, 0, std.math.maxInt(u32)); + _ = try t.scanFrom(tab, gpa, content, &at, std.math.maxInt(u32), true, 0, std.math.maxInt(u32)); t.pending = null; } @@ -512,7 +512,7 @@ pub fn scan(t: *Tables, gpa: std.mem.Allocator, content: []const u8) !void { /// appending them; with `fences`, keep the fences. With a budget, stop /// when it is spent, `at` where to go on from. Whether it reached the end /// (or `stop`). -fn scanFrom(t: *Tables, gpa: std.mem.Allocator, content: []const u8, at: *Resume, stop: u32, fences: bool, budget_ns: u64, max_lines: u32) !bool { +fn scanFrom(t: *Tables, tab: u16, gpa: std.mem.Allocator, content: []const u8, at: *Resume, stop: u32, fences: bool, budget_ns: u64, max_lines: u32) !bool { var fence = at.fence; var prev_blank = at.prev_blank; var line = lineAt(content, at.at, at.n); @@ -552,7 +552,7 @@ fn scanFrom(t: *Tables, gpa: std.mem.Allocator, content: []const u8, at: *Resume // unless one ends it too (`| a |`, not `| a`). const lone = header.n + header.more == @intFromBool(header.leading) and !(header.leading and header.trailing); if (!lone and header.cells() == count) { - const last = try t.add(gpa, content, l, delimiter, aligns[0..@min(count, max_cols)]); + const last = try t.add(tab, gpa, content, l, delimiter, aligns[0..@min(count, max_cols)]); line = nextLine(content, last); prev_blank = false; continue; @@ -568,7 +568,7 @@ fn scanFrom(t: *Tables, gpa: std.mem.Allocator, content: []const u8, at: *Resume /// Take the table whose header is `header`: its rows, its columns' widths /// and its width. Returns its last row's line. -fn add(t: *Tables, gpa: std.mem.Allocator, content: []const u8, header: Line, delimiter: Line, aligns: []const Align) !Line { +fn add(t: *Tables, tab: u16, gpa: std.mem.Allocator, content: []const u8, header: Line, delimiter: Line, aligns: []const Align) !Line { var last = delimiter; while (nextLine(content, last)) |row| { if (blank(row.text) or interrupts(row.text)) break; @@ -581,11 +581,11 @@ fn add(t: *Tables, gpa: std.mem.Allocator, content: []const u8, header: Line, de var row: ?Line = header; while (row) |r| : (row = if (r.n == last.n) null else nextLine(content, r)) { const pipes = Pipes.of(r.text); - if (pipes.leading) table.lead = @max(table.lead, @as(u16, @intCast(@min(widthOf(r.text[0..pipes.at[0]]), std.math.maxInt(u16))))); + if (pipes.leading) table.lead = @max(table.lead, @as(u16, @intCast(@min(widthOf(tab, r.text[0..pipes.at[0]]), std.math.maxInt(u16))))); var k: usize = 0; while (k < max_cols) : (k += 1) { const stop = pipes.end(k) orelse break; - const w: u16 = @intCast(@min(widthOf(r.text[pipes.start(k)..stop]), std.math.maxInt(u16))); + const w: u16 = @intCast(@min(widthOf(tab, r.text[pipes.start(k)..stop]), std.math.maxInt(u16))); if (k >= table.cols) { try t.widths.append(gpa, w); try t.aligns.append(gpa, if (k < aligns.len) aligns[k] else .left); @@ -597,8 +597,8 @@ fn add(t: *Tables, gpa: std.mem.Allocator, content: []const u8, header: Line, de row = header; var buf: [max_pads]Pad = undefined; while (row) |r| : (row = if (r.n == last.n) null else nextLine(content, r)) { - var width = widthOf(r.text); - for (t.padsOf(&table, r.n, r.text, &buf)) |pad| width += pad.cells; + var width = widthOf(tab, r.text); + for (t.padsOf(tab, &table, r.n, r.text, &buf)) |pad| width += pad.cells; table.width = @max(table.width, @as(u32, @intCast(@min(width, std.math.maxInt(u32))))); } try t.list.append(gpa, table); @@ -608,11 +608,11 @@ fn add(t: *Tables, gpa: std.mem.Allocator, content: []const u8, header: Line, de /// The pads of one of `table`'s rows, by byte, in order. No pad is ever at /// byte 0: a row is drawn from its first byte, so there is no cell before /// it to give. -pub fn padsOf(t: *const Tables, table: *const Table, line: usize, text: []const u8, out: *[max_pads]Pad) []Pad { +pub fn padsOf(t: *const Tables, tab: u16, table: *const Table, line: usize, text: []const u8, out: *[max_pads]Pad) []Pad { const pipes = Pipes.of(text); var n: usize = 0; if (pipes.leading and pipes.at[0] > 0) { - const w = widthOf(text[0..pipes.at[0]]); + const w = widthOf(tab, text[0..pipes.at[0]]); if (w < table.lead) { out[n] = .{ .at = pipes.at[0], .cells = @intCast(table.lead - w) }; n += 1; @@ -622,7 +622,7 @@ pub fn padsOf(t: *const Tables, table: *const Table, line: usize, text: []const while (k < table.cols) : (k += 1) { const stop = pipes.end(k) orelse break; const from = pipes.start(k); - const w = widthOf(text[from..stop]); + const w = widthOf(tab, text[from..stop]); const want = t.widths.items[table.col0 + k]; if (w >= want) continue; const missing: u16 = @intCast(want - w); @@ -676,7 +676,7 @@ pub fn between(pads: []const Pad, from: usize, to: usize) i32 { /// The byte at display column `col` of a row shown from byte `from`, its /// pads counted: a pad's cells are its byte's, as a tab's are the tab's. /// Past the end, a virtual column a cell (File.rawAtDisplay). -pub fn byteAt(text: []const u8, pads: []const Pad, from_raw: usize, col: usize) usize { +pub fn byteAt(tab: u16, text: []const u8, pads: []const Pad, from_raw: usize, col: usize) usize { if (from_raw >= text.len) return from_raw +| col; var at = modal.graphemeStart(text, from_raw); var k: usize = 0; @@ -689,7 +689,7 @@ pub fn byteAt(text: []const u8, pads: []const Pad, from_raw: usize, col: usize) if (col < used) return at; } const end = modal.nextGrapheme(text, at); - used += File.graphemeDisplayWidth(text[at..end]); + used += File.graphemeDisplayWidth(tab, text[at..end]); if (col < used) return at; at = end; } @@ -727,11 +727,11 @@ pub fn paint(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw: const body_y = p.bodyTop(pane, r); var vr: u16 = 0; while (vr < body_h) : (vr += 1) { - const w = pane.wrapAt(vr); + const w = pane.wrapAt(p.settings.tab, vr); const table = File.rowTable(pane, w.line) orelse continue; const text = File.sourceLine(pane, w.line); var buf: [max_pads]Pad = undefined; - const pads = f.tables.padsOf(table, @intCast(w.line), text, &buf); + const pads = f.tables.padsOf(p.settings.tab, table, @intCast(w.line), text, &buf); const pipes = Pipes.of(text); const delimiter = w.line == table.first + 1; const header = w.line == table.first; @@ -759,7 +759,7 @@ pub fn paint(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw: if (col >= tw) break; } const end = modal.nextGrapheme(text, at); - const cells = File.graphemeDisplayWidth(text[at..end]); + const cells = File.graphemeDisplayWidth(p.settings.tab, text[at..end]); const cell = s.at(tx + @as(u16, @intCast(col)), y); const pipe = q < pipes.n and pipes.at[q] == at; if (pipe) { @@ -819,7 +819,7 @@ fn testPane(p: *Pardes, content: []const u8, frame: std.mem.Allocator) !*Pane { test "tables: a pipe table's columns, alignments and pads, by line" { var t: Tables = .{}; defer t.deinit(testing.allocator); - try t.scan(testing.allocator, sample); + try t.scan(config.tab_width, testing.allocator, sample); try testing.expectEqual(@as(usize, 1), t.list.items.len); const table = t.list.items[0]; try testing.expectEqual(@as(u32, 2), table.first); @@ -832,11 +832,11 @@ test "tables: a pipe table's columns, alignments and pads, by line" { const fig = "| fig || |"; try testing.expectEqualSlices(Pad, &.{ .{ .at = 6, .cells = 2 }, .{ .at = 7, .cells = 5 }, .{ .at = 8, .cells = 8 }, .{ .at = 9, .cells = 8 }, - }, t.padsOf(&table, 6, fig, &buf)); + }, t.padsOf(config.tab_width, &table, 6, fig, &buf)); // `| apple | 3 | red |`: right-aligned 3 pads before its first byte. try testing.expectEqualSlices(Pad, &.{ .{ .at = 9, .cells = 2 }, .{ .at = 13, .cells = 6 }, .{ .at = 18, .cells = 6 }, - }, t.padsOf(&table, 4, "| apple | 3 | red |", &buf)); + }, t.padsOf(config.tab_width, &table, 4, "| apple | 3 | red |", &buf)); // Every row laid out is one width: the table's. try testing.expectEqual(@as(u32, 1 + 7 + 1 + 5 + 1 + 17 + 1), table.width); // Not tables: a fence's rows, counts that differ, a delimiter alone. @@ -846,7 +846,7 @@ test "tables: a pipe table's columns, alignments and pads, by line" { "|---|---|\n", "| a\n|---\n", }) |text| { - try t.scan(testing.allocator, text); + try t.scan(config.tab_width, testing.allocator, text); try testing.expectEqual(@as(usize, 0), t.list.items.len); } } @@ -854,26 +854,26 @@ test "tables: a pipe table's columns, alignments and pads, by line" { test "tables: every byte's cell maps back to it, and every pad cell to the byte after it" { var t: Tables = .{}; defer t.deinit(testing.allocator); - try t.scan(testing.allocator, sample); + try t.scan(config.tab_width, testing.allocator, sample); const table = &t.list.items[0]; var lines = std.mem.splitScalar(u8, sample, '\n'); var n: usize = 0; while (lines.next()) |text| : (n += 1) { if (n < table.first or n >= table.end) continue; var buf: [max_pads]Pad = undefined; - const pads = t.padsOf(table, n, text, &buf); + const pads = t.padsOf(config.tab_width, table, n, text, &buf); var col: usize = 0; for (text, 0..) |_, b| { // The pad before b: each of its cells is b's. - const start = File.displayWidth(text[0..b]) + @as(usize, @intCast(between(pads, 0, b))); - while (col < start) : (col += 1) try testing.expectEqual(b, byteAt(text, pads, 0, col)); - try testing.expectEqual(b, byteAt(text, pads, 0, col)); + const start = File.displayWidth(config.tab_width, text[0..b]) + @as(usize, @intCast(between(pads, 0, b))); + while (col < start) : (col += 1) try testing.expectEqual(b, byteAt(config.tab_width, text, pads, 0, col)); + try testing.expectEqual(b, byteAt(config.tab_width, text, pads, 0, col)); col += 1; } // Past the end, a virtual column a cell. - try testing.expectEqual(text.len + 2, byteAt(text, pads, 0, col + 2)); + try testing.expectEqual(text.len + 2, byteAt(config.tab_width, text, pads, 0, col + 2)); // From a scrolled start, the pads before it are not counted. - try testing.expectEqual(@as(usize, 2), byteAt(text, pads, 2, 0)); + try testing.expectEqual(@as(usize, 2), byteAt(config.tab_width, text, pads, 2, 0)); } } @@ -892,7 +892,7 @@ test "tables: a markdown table is drawn aligned, its bytes in order, the caret a const text = File.sourceLine(pane, @intCast(line)); var k: usize = 0; for (text, 0..) |b, i| { - const x = text_x + @as(u16, @intCast(File.displayOffset(pane, @intCast(line), 0, @intCast(i)))); + const x = text_x + @as(u16, @intCast(File.displayOffset(config.tab_width, pane, @intCast(line), 0, @intCast(i)))); const cell = p.surface.at(x, body_y + @as(u16, @intCast(line))); if (b == '|') { if (pipe_x[k]) |want| try testing.expectEqual(want, x) else pipe_x[k] = x; @@ -927,20 +927,20 @@ test "tables: a markdown table is drawn aligned, its bytes in order, the caret a while (col < pipe_x[3].? - text_x + 1) : (col += 1) { p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = text_x + col, .row = y } }); p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = text_x + col, .row = y } }); - const want = File.byteAtRowDisplay(pane, fig, 0, col); + const want = File.byteAtRowDisplay(config.tab_width, pane, fig, 0, col); try testing.expectEqual(fig, pane.body.cur_row); try testing.expectEqual(want, pane.body.cur_col); try testing.expect(want < text.len); _ = frame.reset(.retain_capacity); _ = try p.render(frame.allocator()); const caret = p.surface.cursor orelse return error.NoCaret; - try testing.expectEqual(text_x + @as(u16, @intCast(File.displayOffset(pane, fig, 0, want))), caret.x); + try testing.expectEqual(text_x + @as(u16, @intCast(File.displayOffset(config.tab_width, pane, fig, 0, want))), caret.x); // The caret is on the cell clicked, or on the glyph after its pad. try testing.expect(caret.x >= text_x + col); } // A pad cell: the empty second cell's five, all the `|` after them. const empty_x = pipe_x[1].? - text_x + 1; - for (0..5) |i| try testing.expectEqual(@as(i32, 7), File.byteAtRowDisplay(pane, fig, 0, @intCast(empty_x + i))); + for (0..5) |i| try testing.expectEqual(@as(i32, 7), File.byteAtRowDisplay(config.tab_width, pane, fig, 0, @intCast(empty_x + i))); } test "tables: typing in a cell re-aligns the table live, and j/k keep the column shown" { @@ -964,7 +964,7 @@ test "tables: typing in a cell re-aligns the table live, and j/k keep the column for (text, 0..) |b, i| { if (b != '|') continue; k += 1; - if (k == 3) try testing.expectEqual(@as(i32, 1 + 7 + 1 + 12), File.displayOffset(pane, @intCast(line), 0, @intCast(i))); + if (k == 3) try testing.expectEqual(@as(i32, 1 + 7 + 1 + 12), File.displayOffset(config.tab_width, pane, @intCast(line), 0, @intCast(i))); } } // k from the kiwi row's `and` keeps its screen column: the apple @@ -974,10 +974,10 @@ test "tables: typing in a cell re-aligns the table live, and j/k keep the column pane.body.cur_col = @intCast(std.mem.indexOf(u8, File.sourceLine(pane, 5), "and").?); pane.body.vsel.active = false; pane.body.sticky_col = -1; - const shown = File.displayOffset(pane, 5, 0, pane.body.cur_col); + const shown = File.displayOffset(config.tab_width, pane, 5, 0, pane.body.cur_col); p.update(.{ .key = .{ .cp = 'k', .text = "k" } }); try testing.expectEqual(@as(i32, 4), pane.body.cur_row); - try testing.expectEqual(shown, File.displayOffset(pane, 4, 0, pane.body.cur_col)); + try testing.expectEqual(shown, File.displayOffset(config.tab_width, pane, 4, 0, pane.body.cur_col)); } test "tables: an edit's tables, shifted and found again around it, are the whole text's" { @@ -1004,9 +1004,9 @@ test "tables: an edit's tables, shifted and found again around it, are the whole @memcpy(new[at + grow ..], old[at + cut ..]); const scans = f.tables.scans; File.setContent(p, f, new); - f.tables.ensure(p.gpa, f); + f.tables.ensure(config.tab_width, p.gpa, f); if (f.tables.scans == scans) reflowed += 1; - try whole.scan(testing.allocator, f.content); + try whole.scan(config.tab_width, testing.allocator, f.content); testing.expectEqual(whole.list.items.len, f.tables.list.items.len) catch |e| { std.debug.print("round {d}\n{s}\n", .{ round, f.content }); return e; @@ -1060,7 +1060,7 @@ test "tables: a big text's tables are read a frame's budget at a time from the t try testing.expect(reached < File.nlines(p.gpa, f)); var whole: Tables = .{}; defer whole.deinit(testing.allocator); - try whole.scan(testing.allocator, f.content); + try whole.scan(config.tab_width, testing.allocator, f.content); try testing.expectEqual(whole.list.items.len, f.tables.list.items.len); for (whole.list.items, f.tables.list.items) |w, mine| { try testing.expectEqual(w.first, mine.first); @@ -1079,7 +1079,7 @@ test "tables: a table wider than a wrapping pane is shown as its source, laid ou try testing.expect(File.wrapWidth(pane, true) < 34); try testing.expect(File.rowTable(pane, 2) == null); // Source: a pipe is a pipe, at its source column. - try testing.expectEqual(@as(i32, 7), File.displayOffset(pane, 5, 0, 7)); + try testing.expectEqual(@as(i32, 7), File.displayOffset(config.tab_width, pane, 5, 0, 7)); try testing.expect(p.executeBuiltinLine(0, "Wrap off")); p.sync(); _ = frame.reset(.retain_capacity); diff --git a/core/Term.zig b/core/Term.zig index ce462d81..fde36420 100644 --- a/core/Term.zig +++ b/core/Term.zig @@ -289,14 +289,14 @@ pub fn editRows(s: *State, arena: std.mem.Allocator, first: usize, count: usize) /// How many bytes of one of its rows, as `viewport` and `textRows` give it /// uncut, are the prompt it starts with: the prompt's columns, measured in /// the row's text as the core measures a display. -pub fn promptPrefix(s: ?*State, row: i32, raw: []const u8) usize { +pub fn promptPrefix(tab: u16, s: ?*State, row: i32, raw: []const u8) usize { const state = s orelse return 0; if (row < 0) return 0; const cut = the().promptCut(state.impl, row) orelse return 0; return switch (cut) { .keep => 0, .blank => raw.len, - .cut => |cols| @min(raw.len, File.rawAtDisplay(raw, cols)), + .cut => |cols| @min(raw.len, File.rawAtDisplay(tab, raw, cols)), }; } diff --git a/core/Text.zig b/core/Text.zig index 5acd6146..51d660cf 100644 --- a/core/Text.zig +++ b/core/Text.zig @@ -162,8 +162,8 @@ pub fn dropSels(t: *Text) void { /// Bring the cursor into view (acme's textshow). Only a body scrolls to it; /// the tagline follows its caret where it is drawn, and a prompt's answer is /// drawn whole. -pub fn show(t: *Text) void { - if (t.what == .body) if (t.pane()) |w| w.ensureCursorVisible(); +pub fn show(t: *Text, tab: u16) void { + if (t.what == .body) if (t.pane()) |w| w.ensureCursorVisible(tab); } pub fn toModalCursor(t: *Text) modal.Cursor { @@ -176,15 +176,15 @@ pub fn fromModalCursor(t: *Text, c: modal.Cursor) void { t.cur_pinned = true; } -pub fn insertVerticalCursor(lines: []const []const u8, c: modal.Cursor, down: bool) modal.Cursor { +pub fn insertVerticalCursor(tab: u16, lines: []const []const u8, c: modal.Cursor, down: bool) modal.Cursor { if (lines.len == 0) return c; // A cursor past the lines (its text changed under it) moves from the last. const row = if (down) @min(c.row + 1, lines.len - 1) else @min(c.row, lines.len) -| 1; const target = lines[row]; if (target.len == 0) return .{ .row = row, .col = 0 }; const source = if (c.row < lines.len) lines[c.row] else ""; - const goal = File.rawDisplayCol(source, c.col); - const mapped = File.rawAtDisplay(target, goal); + const goal = File.rawDisplayCol(tab, source, c.col); + const mapped = File.rawAtDisplay(tab, target, goal); const last = modal.prevGrapheme(target, target.len); return .{ .row = row, .col = modal.graphemeStart(target, @min(mapped, last)) }; } @@ -219,7 +219,7 @@ pub fn rangeCells(text: []const u8, r: modal.Selection) Cells { return .{ .cur = r.head, .anc = r.head }; } -pub fn setRange(t: *Text, text: []const u8, row0: i32, r0: modal.Selection, explicit: bool) void { +pub fn setRange(t: *Text, tab: u16, text: []const u8, row0: i32, r0: modal.Selection, explicit: bool) void { var r = r0; if (r.anchor == r.head) r.head = modal.nextGrapheme(text, r.head); // min_width_1 const off = rangeCells(text, r); @@ -239,7 +239,7 @@ pub fn setRange(t: *Text, text: []const u8, row0: i32, r0: modal.Selection, expl t.cur_pinned = true; t.sticky_col = -1; t.normal.clear(); - t.show(); + t.show(tab); } pub fn ranges(t: *Text, text: []const u8, row0: i32, out: *[max_selections]modal.Selection) struct { n: usize, pri: usize } { @@ -266,7 +266,7 @@ pub fn ranges(t: *Text, text: []const u8, row0: i32, out: *[max_selections]modal return .{ .n = n, .pri = pri }; } -pub fn setRanges(t: *Text, text: []const u8, in: []const modal.Selection, sticky: []const i32, pri0: usize, explicit: bool) void { +pub fn setRanges(t: *Text, tab: u16, text: []const u8, in: []const modal.Selection, sticky: []const i32, pri0: usize, explicit: bool) void { if (in.len == 0) return; // helix asserts non-empty; here it just means "no change" var r: [max_selections]modal.Selection = undefined; var st: [max_selections]i32 = undefined; @@ -311,7 +311,7 @@ pub fn setRanges(t: *Text, text: []const u8, in: []const modal.Selection, sticky if (pri == i) pri = k; } n = k + 1; - setRange(t, text, 0, r[pri], explicit); + setRange(t, tab, text, 0, r[pri], explicit); if (n > 1 and !t.reserveSels()) return; // no room: the primary alone t.sticky_col = st[pri]; var w: usize = 0; @@ -334,7 +334,7 @@ pub fn setRanges(t: *Text, text: []const u8, in: []const modal.Selection, sticky /// helix `scroll` without cursor sync (Ctrl-f/b, PgUp/PgDn, zj/zk): shift /// the view, then snap a fallen-out cursor to the near scrolloff edge, col 0 -pub fn scrollViewMove(t: *Text, text: []const u8, range: modal.Selection, delta: i32) void { +pub fn scrollViewMove(t: *Text, tab: u16, text: []const u8, range: modal.Selection, delta: i32) void { // a view to move through is a body's; a tag or an answer is all shown if (t.what != .body) return; const w = t.pane() orelse return; @@ -348,13 +348,13 @@ pub fn scrollViewMove(t: *Text, text: []const u8, range: modal.Selection, delta: const head = File.textLineStart(t, text, @intCast(snap)); if (head <= cur) return; const anchor = if (t.select) range.anchor else head; - setRange(t, text, 0, .{ .anchor = anchor, .head = head }, false); + setRange(t, tab, text, 0, .{ .anchor = anchor, .head = head }, false); } else { const snap: i32 = @max(0, @min(top + @as(i32, w.rows) - margin - 1, last_row)); const head = File.textLineStart(t, text, @intCast(snap)); if (head >= cur) return; const anchor = if (t.select) range.anchor else head; - setRange(t, text, 0, .{ .anchor = anchor, .head = head }, false); + setRange(t, tab, text, 0, .{ .anchor = anchor, .head = head }, false); } } @@ -368,7 +368,7 @@ pub fn rangeLineSpan(text: []const u8, r: modal.Selection) struct { start: usize /// pull the cursor back inside `text` after a rewrite; `row0` is the /// absolute surface row of its first line (0 for a file) -pub fn clampCursor(t: *Text, text: []const u8, row0: i32) void { +pub fn clampCursor(t: *Text, tab: u16, text: []const u8, row0: i32) void { const n = modal.lineCount(text); const row: usize = @min(@as(usize, @intCast(@max(0, t.cur_row - row0))), if (n == 0) 0 else n - 1); const llen = modal.lineSlice(text, row).len; @@ -376,7 +376,7 @@ pub fn clampCursor(t: *Text, text: []const u8, row0: i32) void { t.cur_col = @intCast(@min(@as(usize, @intCast(@max(0, t.cur_col))), llen)); t.cur_pinned = true; t.vsel.active = false; - t.show(); + t.show(tab); } // ---- undo: the edits a text took, as a journal ---- diff --git a/core/ansi.zig b/core/ansi.zig index 6a5d0416..6c23fee6 100644 --- a/core/ansi.zig +++ b/core/ansi.zig @@ -438,7 +438,7 @@ pub fn recolorDiffOutput(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, t view.* = null; const line = shown.next() orelse continue; const vr: i32 = @intCast(vi); - const w = pane.wrapAt(vr); + const w = pane.wrapAt(p.settings.tab, vr); const row_i: i32 = if (raw) @as(i32, @intCast(panes.Term.grid(pane.terminal).offset)) + vr else w.line; if (row_i < 0 or row_i >= @as(i64, @intCast(rows.len))) continue; const row: usize = @intCast(row_i); @@ -466,7 +466,7 @@ pub fn recolorDiffOutput(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, t while (c < line.len and screen_c < tw) { const grapheme_end = modal.nextGrapheme(line, c); if (grapheme_end <= c) break; - const cells = panes.File.graphemeDisplayWidth(line[c..grapheme_end]); + const cells = panes.File.graphemeDisplayWidth(p.settings.tab, line[c..grapheme_end]); const style = styles[base + view.at + c]; const prefix = view.at + c == 0 and (line[0] == '+' or line[0] == '-'); // On an added or removed line, what the program coloured red or diff --git a/core/body_layer.zig b/core/body_layer.zig index 101bbe9c..73c9dd48 100644 --- a/core/body_layer.zig +++ b/core/body_layer.zig @@ -29,7 +29,7 @@ const Layer = @import("Layer.zig"); // ---- drawing a pane body into the surface ---- fn paintTerminalSelection(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, rows: []const Pane.PointerRow, bg: [3]u8, fg: ?[3]u8) void { - const body = bodyText(p.scratch.allocator(), pane) catch return; + const body = bodyText(p.settings.tab, p.scratch.allocator(), pane) catch return; const raw = pane.body.mode == .tty; const tx = r.x + config.GUTTER; const width = r.w -| config.GUTTER; @@ -38,7 +38,7 @@ fn paintTerminalSelection(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, rows: [ var visible: i32 = 0; while (lines.next()) |line| : (visible += 1) { if (visible >= r.h -| pane.tag_rows) break; - const source_row = if (raw) @as(i32, @intCast(panes.Term.grid(pane.terminal).offset)) + visible else pane.wrapAt(visible).line; + const source_row = if (raw) @as(i32, @intCast(panes.Term.grid(pane.terminal).offset)) + visible else pane.wrapAt(p.settings.tab, visible).line; for (rows) |row| { const target = if (row.raw_terminal) (if (raw) row.row else pane.surfRow(row.row)) @@ -51,15 +51,15 @@ fn paintTerminalSelection(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, rows: [ lo -|= row.prompt_bytes; hi -|= row.prompt_bytes; } else if (!row.raw_terminal and raw) { - const prefix = panes.Term.promptPrefix(pane.terminal, source_row, line); + const prefix = panes.Term.promptPrefix(p.settings.tab, pane.terminal, source_row, line); lo += prefix; hi += prefix; } lo = modal.graphemeStart(line, @min(lo, line.len)); hi = @min(hi, line.len); if (lo >= hi) continue; - const col = panes.File.rawDisplayCol(line, lo); - const end = @min(width, if (row.to_edge and hi == line.len) width else panes.File.rawDisplayCol(line, hi)); + const col = panes.File.rawDisplayCol(p.settings.tab, line, lo); + const end = @min(width, if (row.to_edge and hi == line.len) width else panes.File.rawDisplayCol(p.settings.tab, line, hi)); if (col < end) s.tint(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(visible)), @intCast(end - col), bg, fg); } } @@ -68,13 +68,13 @@ fn paintTerminalSelection(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, rows: [ /// Whether `col` lies past the last column its visible row shows: the last /// visible row of a line owns every column after its start (wrapRow), so a /// head millions of bytes along a long line is on that row, off the view. -fn pastView(pane: *Pane, body: []const u8, line: i32, row: i32, at: i32, col: i32, tw: u16) bool { +fn pastView(tab: u16, pane: *Pane, body: []const u8, line: i32, row: i32, at: i32, col: i32, tw: u16) bool { const text = if (pane.file != null) panes.File.sourceLine(pane, line) else modal.lineSlice(body, @intCast(@max(0, row))); const from: usize = @intCast(@max(0, at)); const to: usize = @intCast(@max(0, col)); if (from >= text.len) return to >= from +| tw; // A file row's last shown byte counts its table pads (File.rowPads). - const shown: usize = if (pane.file != null) @intCast(panes.File.byteAtRowDisplay(pane, line, at, tw)) else from + panes.File.byteAtDisplay(text[from..], tw); + const shown: usize = if (pane.file != null) @intCast(panes.File.byteAtRowDisplay(tab, pane, line, at, tw)) else from + panes.File.byteAtDisplay(tab, text[from..], tw); return to >= shown and to < text.len; } @@ -87,10 +87,10 @@ fn paintSourceSelection(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, rows: []c const prefix: i32 = if (pane.file != null) panes.File.gutterWidth(pane) else 0; var visible: i32 = 0; while (visible < @as(i32, r.h -| pane.tag_rows)) : (visible += 1) { - const source = pane.wrapAt(visible); + const source = pane.wrapAt(p.settings.tab, visible); const line = edit.pointerSourceLine(pane, terminal_lines, source.line); const start = @min(line.len, @as(usize, @intCast(@max(0, source.at)))); - const next = pane.wrapAt(visible + 1); + const next = pane.wrapAt(p.settings.tab, visible + 1); const end = if (next.line == source.line) @min(line.len, @as(usize, @intCast(@max(0, next.at)))) else line.len; for (rows) |row| { if (row.row != source.line) continue; @@ -99,13 +99,13 @@ fn paintSourceSelection(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, rows: []c if (lo >= hi) continue; // A file row through its pads (File.rowPads), as it is drawn. const col = prefix + source.pad + if (pane.file != null) - panes.File.displayOffset(pane, source.line, @intCast(start), @intCast(lo)) + panes.File.displayOffset(p.settings.tab, pane, source.line, @intCast(start), @intCast(lo)) else - @as(i32, @intCast(panes.File.rawDisplayCol(line[start..], lo - start))); + @as(i32, @intCast(panes.File.rawDisplayCol(p.settings.tab, line[start..], lo - start))); const last = @min(width, if (row.to_edge and hi == end) @as(i32, width) else prefix + source.pad + if (pane.file != null) - panes.File.displayOffset(pane, source.line, @intCast(start), @intCast(hi)) + panes.File.displayOffset(p.settings.tab, pane, source.line, @intCast(start), @intCast(hi)) else - @as(i32, @intCast(panes.File.rawDisplayCol(line[start..], hi - start)))); + @as(i32, @intCast(panes.File.rawDisplayCol(p.settings.tab, line[start..], hi - start)))); if (col < last) s.tint(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(visible)), @intCast(last - col), bg, fg); } } @@ -172,7 +172,7 @@ pub fn joinBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, if (pane.file == null) return renderBody(p, s, arena, pane, r, id, active, rail); // The pane's geometry as it is (File.geometry): made by the step that // moved it if one read it, else here, and the same either way. - panes.File.geometry(pane); + panes.File.geometry(p.settings.tab, pane); // Which rows are context rows is decided by the text the body shows: a // layer taller than the grid's rows when there are any. if (pane.collapsed or r.h <= pane.tag_rows or pane.body_rows == 0) @@ -185,7 +185,7 @@ pub fn joinBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, if (layer.cells.len != count) layer.cells = try p.gpa.realloc(layer.cells, count); const temporary_cells = try arena.alloc(Cell, @as(usize, r.w) * (logical_rows + pane.tag_rows)); @memset(temporary_cells, .{}); - var temporary: Surface = .{ .cols = r.w, .rows = @intCast(logical_rows + pane.tag_rows), .cells = temporary_cells }; + var temporary: Surface = .{ .cols = r.w, .rows = @intCast(logical_rows + pane.tag_rows), .cells = temporary_cells, .tab = p.settings.tab }; const synthetic: Rect = .{ .x = 0, .y = 0, .w = r.w, .h = @intCast(logical_rows + pane.tag_rows) }; try renderBody(p, &temporary, arena, pane, synthetic, id, active, null); for (0..logical_rows) |row| { @@ -307,7 +307,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane }; const tz_body = tracy.zone(@src(), "bodyText"); const probe_text = pardes.FrameStats.nowNs(); - const body = try bodyText(arena, pane); + const body = try bodyText(p.settings.tab, arena, pane); p.frames.zone(.body_text, probe_text); tz_body.end(); // A select sweep begun on the tag and dragged into the body marks the @@ -401,7 +401,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane colors.mix(th.sel_bg, page_rgb); var vr: i32 = 0; while (vr + @as(i32, pane.tag_rows) < @as(i32, body_bottom)) : (vr += 1) { - const w = pane.wrapAt(vr); + const w = pane.wrapAt(p.settings.tab, vr); if (w.line < bnd.lo_row or w.line > bnd.hi_row) continue; const visible_line = modal.lineSlice(body, @intCast(vr)); // Only the visible columns are measured: a selection that @@ -415,24 +415,24 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane const shown_to = if (row_at >= row_text.len) row_text.len else if (pane.file != null) - @as(usize, @intCast(panes.File.byteAtRowDisplay(pane, w.line, w.at, tw))) + @as(usize, @intCast(panes.File.byteAtRowDisplay(p.settings.tab, pane, w.line, w.at, tw))) else - row_at + panes.File.byteAtDisplay(row_text[row_at..], tw); + row_at + panes.File.byteAtDisplay(p.settings.tab, row_text[row_at..], tw); const past_view = if (shown_to >= row_text.len) std.math.maxInt(usize) else shown_to; // A row that ends before the selection starts has none of it. if (w.line == bnd.lo_row and @as(usize, @intCast(@max(0, bnd.lo_col))) >= past_view) continue; const cstart: i32 = if (w.line == bnd.lo_row and bnd.lo_col > w.at) (if (pane.file != null) - panes.File.displayOffset(pane, w.line, w.at, bnd.lo_col) + panes.File.displayOffset(p.settings.tab, pane, w.line, w.at, bnd.lo_col) else - panes.File.lineDisplayOffset(visible_line, @intCast(@max(0, w.at)), @intCast(@max(0, bnd.lo_col)))) + vpfx + w.pad + panes.File.lineDisplayOffset(p.settings.tab, visible_line, @intCast(@max(0, w.at)), @intCast(@max(0, bnd.lo_col)))) + vpfx + w.pad else vpfx + w.pad; const cend: i32 = if (w.line == bnd.hi_row and @as(usize, @intCast(@max(0, bnd.hi_col))) < past_view) (if (pane.file != null) - panes.File.displayEndOffset(pane, w.line, w.at, bnd.hi_col) + panes.File.displayEndOffset(p.settings.tab, pane, w.line, w.at, bnd.hi_col) else - panes.File.lineDisplayEndOffset(visible_line, @intCast(@max(0, w.at)), @intCast(@max(0, bnd.hi_col)))) + vpfx + w.pad + panes.File.lineDisplayEndOffset(p.settings.tab, visible_line, @intCast(@max(0, w.at)), @intCast(@max(0, bnd.hi_col)))) + vpfx + w.pad else @as(i32, tw) - 1; const col: i32 = @max(cstart, vpfx); @@ -441,16 +441,16 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane } if (primary and !preview and !hover_only) continue; // the hardware cursor IS the primary's if (hover_only) continue; // quiet preview preserves the source ink - const cw = pane.wrapRow(sr.row, sr.col); + const cw = pane.wrapRow(p.settings.tab, sr.row, sr.col); // A head off the view is measured not at all: its row is not // drawn, and its column may be millions of bytes along. if (cw.row < 0 or cw.row + @as(i32, pane.tag_rows) >= @as(i32, body_bottom)) continue; - if (pastView(pane, body, sr.row, cw.row, cw.at, sr.col, tw)) continue; + if (pastView(p.settings.tab, pane, body, sr.row, cw.row, cw.at, sr.col, tw)) continue; const crow = cw.row + @as(i32, pane.tag_rows); const ccol = (if (pane.file != null) - panes.File.displayOffset(pane, sr.row, cw.at, sr.col) + panes.File.displayOffset(p.settings.tab, pane, sr.row, cw.at, sr.col) else - panes.File.lineDisplayOffset( + panes.File.lineDisplayOffset(p.settings.tab, modal.lineSlice(body, @intCast(@max(0, cw.row))), @intCast(@max(0, cw.at)), @intCast(@max(0, sr.col)), @@ -475,11 +475,11 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane for ([_]u8{ letters[i / letters.len], letters[i % letters.len] }) |letter| { const pos = modal.positionAt(flat, at); const row: i32 = @intCast(pos.row); - const wp = pane.wrapRow(row, @intCast(pos.col)); + const wp = pane.wrapRow(p.settings.tab, row, @intCast(pos.col)); const cx = if (pane.file != null) - @as(i32, panes.File.gutterWidth(pane)) + wp.pad + panes.File.displayOffset(pane, row, wp.at, @intCast(pos.col)) + @as(i32, panes.File.gutterWidth(pane)) + wp.pad + panes.File.displayOffset(p.settings.tab, pane, row, wp.at, @intCast(pos.col)) else - panes.File.lineDisplayOffset(modal.lineSlice(flat, pos.row), @intCast(@max(0, wp.at)), pos.col); + panes.File.lineDisplayOffset(p.settings.tab, modal.lineSlice(flat, pos.row), @intCast(@max(0, wp.at)), pos.col); if (wp.row >= 0 and wp.row < body_h and cx >= 0 and cx < tw) s.set(tx + @as(u16, @intCast(cx)), body_y + @as(u16, @intCast(wp.row)), &.{letter}, style); at = modal.nextGrapheme(flat, at); @@ -494,17 +494,17 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane const grid = panes.Term.grid(pane.terminal); const crow = if (pane.body.cur_pinned) pane.body.cur_row else pane.surfRow(@as(i32, grid.cursor_y) + @as(i32, @intCast(grid.offset))); const ccol = if (pane.body.cur_pinned) pane.body.cur_col else @as(i32, grid.cursor_x); - const cwp = pane.wrapRow(crow, ccol); + const cwp = pane.wrapRow(p.settings.tab, crow, ccol); const prow = cwp.row + @as(i32, pane.tag_rows); // Off the view, the cursor is not measured (its column may be // millions of bytes along a line whose start is shown). - if (cwp.row >= 0 and prow < body_bottom and !pastView(pane, body, crow, cwp.row, cwp.at, ccol, tw)) { + if (cwp.row >= 0 and prow < body_bottom and !pastView(p.settings.tab, pane, body, crow, cwp.row, cwp.at, ccol, tw)) { // Files store source-byte columns; the Surface stores display // cells, so account for every expanded tab before the cursor. const cx = if (pane.file != null) - @as(i32, panes.File.gutterWidth(pane)) + cwp.pad + panes.File.displayOffset(pane, crow, cwp.at, ccol) + @as(i32, panes.File.gutterWidth(pane)) + cwp.pad + panes.File.displayOffset(p.settings.tab, pane, crow, cwp.at, ccol) else if (pane.body.cur_pinned) - panes.File.lineDisplayOffset( + panes.File.lineDisplayOffset(p.settings.tab, modal.lineSlice(body, @intCast(@max(0, cwp.row))), @intCast(@max(0, cwp.at)), @intCast(@max(0, ccol)), @@ -540,13 +540,13 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane }; } -pub fn bodyText(arena: std.mem.Allocator, pane: *Pane) ![]const u8 { +pub fn bodyText(tab: u16, arena: std.mem.Allocator, pane: *Pane) ![]const u8 { if (pane.addon != null) { const buf = try arena.alloc(u8, pane.rows -| 1); @memset(buf, '\n'); return buf; } - if (pane.file) |*f| return panes.File.bodyText(arena, pane, f); + if (pane.file) |*f| return panes.File.bodyText(tab, arena, pane, f); // A terminal's: the rows its view shows (outside raw mode its prompts // cut off), the edit copy's lines over the rows the copy covers. const vp: []const []const u8 = if (pane.terminal) |state| try panes.Term.viewport(state, arena, pane.body.mode != .tty) else &.{}; diff --git a/core/config.zig b/core/config.zig index ebc5d056..5f63268e 100644 --- a/core/config.zig +++ b/core/config.zig @@ -350,11 +350,6 @@ pub const PREFIX_W: u16 = 5; pub const default_incl = [_][]const u8{ "/usr/include", "/usr/local/include" }; pub const tab_width: u16 = 4; -/// The width a tab is drawn and counted at now: `Tab N` (Runtime.tab) sets -/// it, a new session starts it at tab_width. ponytail: one for the process, -/// as the session's setting is one; per pane would mean handing a pane to -/// every width function (File.graphemeDisplayWidth and its ~130 callers). -pub var tab_now: u16 = tab_width; comptime { if (tab_width == 0) @compileError("config.tab_width must be greater than zero"); } @@ -665,8 +660,9 @@ pub const Runtime = struct { tagline_percent: u8 = 100, } = .{}, - /// acme's Tab: a tab's width in cells, in every pane (config.tab_now - /// is what the drawing and the column arithmetic read). + /// acme's Tab: a tab's width in cells, in every pane: what the drawing + /// (Surface.tab) and the column arithmetic (File.graphemeDisplayWidth's + /// `tab`, handed down from here) read. tab: u16 = tab_width, callstack_depth: u8 = @import("lsp/lsp.zig").callstack_default_depth, diff --git a/core/draw.zig b/core/draw.zig index 7091f61e..f4b08635 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -148,8 +148,8 @@ const Printed = struct { left: u16, dropped: usize }; /// band loses its HEAD: the end is the part that says something -- a /// path's file name, an error's reason -- and `dropped` is how many /// columns of it went. -fn printRight(s: *Surface, x: u16, row: u16, w: u16, text: []const u8, style: CellStyle) Printed { - const width = panes.File.displayWidth(text); +fn printRight(tab: u16, s: *Surface, x: u16, row: u16, w: u16, text: []const u8, style: CellStyle) Printed { + const width = panes.File.displayWidth(tab, text); if (width <= w) { const left: u16 = @intCast(x + w - width); _ = s.print(left, row, @intCast(width), text, style); @@ -158,10 +158,10 @@ fn printRight(s: *Surface, x: u16, row: u16, w: u16, text: []const u8, style: Ce // Whole glyphs only: a cut inside a wide one would leave the rest a // column too wide and clip its LAST glyph instead of the first. var dropped = width - w; - var start = panes.File.rawAtDisplay(text, dropped); - if (panes.File.rawDisplayCol(text, start) < dropped) { + var start = panes.File.rawAtDisplay(tab, text, dropped); + if (panes.File.rawDisplayCol(tab, text, start) < dropped) { dropped += 1; - start = panes.File.rawAtDisplay(text, dropped); + start = panes.File.rawAtDisplay(tab, text, dropped); } const left: u16 = @intCast(x + w - (width - dropped)); _ = s.print(left, row, @intCast(width - dropped), text[start..], style); @@ -189,9 +189,9 @@ fn joinNotice(p: *Pardes, s: *Surface, arena: std.mem.Allocator, region: Region) if (text.len == 0 or r.w <= TAG_TEXT_INSET) { s.fill(region.rect.x, region.rect.y, chip, 1, .{ .bg = .{ .rgb = bg }, .font_role = .tagline }); if (text.len == 0) return; - const printed = printRight(s, region.rect.x, region.rect.y, chip -| 1, text, .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .font_role = .tagline }); + const printed = printRight(p.settings.tab, s, region.rect.x, region.rect.y, chip -| 1, text, .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .font_role = .tagline }); if (kind != .prompt or id != v.active or pane.prompt == .del_side or pane.prompt == .repl_choice) return; - const prompt_col = panes.File.displayWidth(text[0..@min(@as(usize, @intCast(@max(0, pane.input.cur_col))), text.len)]); + const prompt_col = panes.File.displayWidth(p.settings.tab, text[0..@min(@as(usize, @intCast(@max(0, pane.input.cur_col))), text.len)]); if (prompt_col < printed.dropped) return; s.cursor = .{ .x = @intCast(printed.left + (prompt_col - printed.dropped)), .y = region.rect.y, .bar = pane.input.mode == .insert }; return; @@ -203,14 +203,14 @@ fn joinNotice(p: *Pardes, s: *Surface, arena: std.mem.Allocator, region: Region) // something. const capacity = layout.tagCapacity(p, chip); const room = capacity -| 1; - const shown = panes.File.displayWidth(text); + const shown = panes.File.displayWidth(p.settings.tab, text); var kept = text; if (shown > room) { - var start = panes.File.rawAtDisplay(text, shown - room); - if (panes.File.rawDisplayCol(text, start) < shown - room) start = panes.File.rawAtDisplay(text, shown - room + 1); + var start = panes.File.rawAtDisplay(p.settings.tab, text, shown - room); + if (panes.File.rawDisplayCol(p.settings.tab, text, start) < shown - room) start = panes.File.rawAtDisplay(p.settings.tab, text, shown - room + 1); kept = text[start..]; } - const pad = room -| panes.File.displayWidth(kept); + const pad = room -| panes.File.displayWidth(p.settings.tab, kept); const line = try arena.alloc(u8, pad + kept.len); @memset(line[0..pad], ' '); @memcpy(line[pad..], kept); @@ -218,8 +218,8 @@ fn joinNotice(p: *Pardes, s: *Surface, arena: std.mem.Allocator, region: Region) try renderHeaderLayer(p, layer, .notice, @intCast(id), region.rect, line, 0, bg, fg); // The caret rides the band, where the prompt's glyphs are. if (kind == .prompt and id == v.active and pane.prompt != .del_side and pane.prompt != .repl_choice) caret: { - const typed = panes.File.displayWidth(text[0..@min(@as(usize, @intCast(@max(0, pane.input.cur_col))), text.len)]); - const dropped = shown - panes.File.displayWidth(kept); + const typed = panes.File.displayWidth(p.settings.tab, text[0..@min(@as(usize, @intCast(@max(0, pane.input.cur_col))), text.len)]); + const dropped = shown - panes.File.displayWidth(p.settings.tab, kept); if (typed < dropped) break :caret; layer.cursor = .{ .x = @intCast(pad + typed - dropped), .y = 0, .bar = pane.input.mode == .insert }; } @@ -252,6 +252,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { } s.cols = v.screen_w; s.rows = v.screen_h; + s.tab = p.settings.tab; s.cursor = null; s.pointer_shape = .arrow; // A look-hover preview means the pointed word is a real Look or Exec @@ -593,7 +594,7 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v return; } var widest: usize = 0; - for (0..viewport.h) |line| widest = @max(widest, panes.File.displayWidth(modal.lineSlice(text, line + top))); + for (0..viewport.h) |line| widest = @max(widest, panes.File.displayWidth(p.settings.tab, modal.lineSlice(text, line + top))); const columns: u16 = @intCast(@min(std.math.maxInt(u16), @max(layout.tagCapacity(p, viewport.w), widest + 1))); const count = @as(usize, columns) * viewport.h; if (layer.cells.len != count) layer.cells = try p.gpa.realloc(layer.cells, count); @@ -618,10 +619,10 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v for (0..viewport.h) |index| { const line: u16 = @intCast(index); const shown = modal.lineSlice(text, index + top); - var surface: Surface = .{ .cols = columns, .rows = 1, .cells = layer.cells[index * columns ..][0..columns] }; + var surface: Surface = .{ .cols = columns, .rows = 1, .cells = layer.cells[index * columns ..][0..columns], .tab = p.settings.tab }; surface.fill(0, 0, columns, 1, .{ .bg = .{ .rgb = bg }, .font_role = .tagline }); // The scroll is the caret's line's: a shorter line shows nothing. - _ = surface.print(0, 0, columns, shown[@min(shown.len, panes.File.rawAtDisplay(shown, scroll))..], .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .font_role = .tagline }); + _ = surface.print(0, 0, columns, shown[@min(shown.len, panes.File.rawAtDisplay(p.settings.tab, shown, scroll))..], .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .font_role = .tagline }); // The word under the pointer, a Look or Exec target: on a header even // while it is edited, on a notice, and on the grid's copy of either // (joined from this); not on a column a carried column's pointer is @@ -636,9 +637,9 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v v.hover_col - viewport.x else null; - if (col) |hover| if (wordBoundsAtCol(shown, panes.File.rawAtDisplay(shown, hover + scroll))) |bounds| { - var cell = panes.File.rawDisplayCol(shown, bounds.lo) -| scroll; - const end = panes.File.rawDisplayCol(shown, bounds.hi) -| scroll; + if (col) |hover| if (wordBoundsAtCol(shown, panes.File.rawAtDisplay(p.settings.tab, shown, hover + scroll))) |bounds| { + var cell = panes.File.rawDisplayCol(p.settings.tab, shown, bounds.lo) -| scroll; + const end = panes.File.rawDisplayCol(p.settings.tab, shown, bounds.hi) -| scroll; while (cell < end and cell < columns) : (cell += 1) { surface.at(@intCast(cell), 0).style.bg = .{ .rgb = p.theme().tag_sel_bg orelse p.theme().sel_bg }; surface.at(@intCast(cell), 0).style.fg = .{ .rgb = p.theme().sel_fg }; @@ -647,14 +648,14 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v } if (editing) |t| { if (tagline.headerSelection(t, try edit.flatSurface(p.editor(), t), line + v.header_top)) |span| { - var col = panes.File.rawDisplayCol(shown, span.lo) -| scroll; - const end = panes.File.rawDisplayCol(shown, span.hi) -| scroll; + var col = panes.File.rawDisplayCol(p.settings.tab, shown, span.lo) -| scroll; + const end = panes.File.rawDisplayCol(p.settings.tab, shown, span.hi) -| scroll; while (col < end and col < columns) : (col += 1) { surface.at(@intCast(col), 0).style.bg = .{ .rgb = p.theme().tag_sel_bg orelse p.theme().sel_bg }; surface.at(@intCast(col), 0).style.fg = .{ .rgb = p.theme().sel_fg }; } } - const caret = panes.File.rawDisplayCol(shown, @min(@as(usize, @intCast(@max(0, t.cur_col))), shown.len)) -| scroll; + const caret = panes.File.rawDisplayCol(p.settings.tab, shown, @min(@as(usize, @intCast(@max(0, t.cur_col))), shown.len)) -| scroll; const asking = if (p.panes[v.active]) |active| active.prompt != .none else false; if (!asking and t.cur_row == line + v.header_top and caret < columns) layer.cursor = .{ .x = @intCast(caret), .y = line, .bar = t.mode == .insert }; } @@ -671,8 +672,8 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v const end = start + shown.len; if (mine and swept.lo < swept.hi and swept.hi > start and swept.lo < end) { const button = @backingInt(sweep.button); - var col = panes.File.rawDisplayCol(shown, @max(swept.lo, start) - start) -| scroll; - const stop = panes.File.rawDisplayCol(shown, @min(swept.hi, end) - start) -| scroll; + var col = panes.File.rawDisplayCol(p.settings.tab, shown, @max(swept.lo, start) - start) -| scroll; + const stop = panes.File.rawDisplayCol(p.settings.tab, shown, @min(swept.hi, end) - start) -| scroll; while (col < stop and col < columns) : (col += 1) { surface.at(@intCast(col), 0).style.bg = .{ .rgb = body_layer.buttonTints(p.theme())[button] }; surface.at(@intCast(col), 0).style.fg = .{ .rgb = body_layer.buttonInks(p.theme())[button] }; @@ -698,12 +699,12 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r var widest: usize = 0; var split = std.mem.splitScalar(u8, tag, '\n'); for (0..pane.tag_top) |_| _ = split.next(); - for (0..rows) |_| widest = @max(widest, panes.File.displayWidth(split.next() orelse "")); + for (0..rows) |_| widest = @max(widest, panes.File.displayWidth(p.settings.tab, split.next() orelse "")); const columns: u16 = @intCast(@min(std.math.maxInt(u16) - TAG_TEXT_INSET, @max(capacity, widest + 1))); const pitch = @as(usize, columns) + TAG_TEXT_INSET; const storage = try arena.alloc(Cell, pitch * rows); @memset(storage, .{}); - var temporary: Surface = .{ .cols = columns + TAG_TEXT_INSET, .rows = rows, .cells = storage }; + var temporary: Surface = .{ .cols = columns + TAG_TEXT_INSET, .rows = rows, .cells = storage, .tab = p.settings.tab }; try paintPaneTag(p, &temporary, arena, pane, .{ .x = 0, .y = 0, .w = columns + TAG_TEXT_INSET, .h = rows }, id, active); // Window mode (layout.windowKey): the outlined pane's tag in the // selection's colours. @@ -792,7 +793,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, pane.tag_scroll = 0; for (lines[0..rows], 0..) |line, row| { // The scroll is the caret's line's: a shorter row shows nothing. - const start = @min(line.len, panes.File.rawAtDisplay(line, pane.tag_scroll)); + const start = @min(line.len, panes.File.rawAtDisplay(p.settings.tab, line, pane.tag_scroll)); _ = s.print(tx, tag_y + @as(u16, @intCast(row)), tw, line[start..], tag_style); } // The name's tint, in the tag's first line, over whichever rows it @@ -807,8 +808,8 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, const line = lines[row - top]; const from = if (row == a.row) a.col else 0; const to = if (row == b.row) b.col else line.len; - var col = panes.File.rawDisplayCol(line, @min(from, line.len)); - const end = panes.File.rawDisplayCol(line, @min(to, line.len)); + var col = panes.File.rawDisplayCol(p.settings.tab, line, @min(from, line.len)); + const end = panes.File.rawDisplayCol(p.settings.tab, line, @min(to, line.len)); const y = tag_y + @as(u16, @intCast(row - top)); while (col < end and col < tw) : (col += 1) s.at(tx + @as(u16, @intCast(col)), y).style.fg = .{ .rgb = name_fg }; @@ -830,15 +831,15 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, const line = lines[row - top]; const from = if (row == first.row) first.col else 0; const to = @min(line.len, if (row == last.row) last.col else line.len); - const col = panes.File.rawDisplayCol(line, from) -| pane.tag_scroll; - const end = @min(panes.File.rawDisplayCol(line, to) -| pane.tag_scroll, tw); + const col = panes.File.rawDisplayCol(p.settings.tab, line, from) -| pane.tag_scroll; + const end = @min(panes.File.rawDisplayCol(p.settings.tab, line, to) -| pane.tag_scroll, tw); if (col < end) s.tint(tx + @as(u16, @intCast(col)), tag_y + @as(u16, @intCast(row - top)), @intCast(end - col), th.tag_sel_bg orelse th.sel_bg, th.sel_fg); } } } // the caret: bar while typing, block in normal mode (same rule as a body) if (caret) |at| { - const col = panes.File.rawDisplayCol(lines[at.row], at.at) -| pane.tag_scroll; + const col = panes.File.rawDisplayCol(p.settings.tab, lines[at.row], at.at) -| pane.tag_scroll; const mode = if (pane.prompt == .name) pane.input.mode else pane.tag.mode; if (col < tw) s.cursor = .{ .x = tx + @as(u16, @intCast(col)), .y = tag_y + @as(u16, @intCast(at.row)), .bar = mode == .insert }; } diff --git a/core/dump.zig b/core/dump.zig index a4fc0f8d..58560645 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -610,7 +610,6 @@ fn reviveSession(p: *Pardes, previous: ?*Pardes, resumed: bool) !void { p.db = old.db; old.db = .{}; } - config.tab_now = p.settings.tab; // A ThemeFile is a request the host answers by reading the file again; // until it has (and for good if it fails) the theme the dump had shows. if (p.theme_file_path.get().len > 0) { @@ -1001,7 +1000,7 @@ test "a restored pane keeps its dot, as acme's dump keeps a window's" { const p = try Pardes.init(gpa, .{ .tty_only = true }); defer p.deinit(); const pane = try p.setTestFile("one two three\nfour\n"); - ctlfs.pane.setDot(pane, .{ .q0 = 4, .q1 = 7 }); + ctlfs.pane.setDot(config.tab_width, pane, .{ .q0 = 4, .q1 = 7 }); try dumpState(p); const restored = try initFromDump(gpa, .{ .tty_only = true }, p.dump_out.?); defer restored.deinit(); diff --git a/core/edit.zig b/core/edit.zig index ea8f9e8a..d91620c4 100644 --- a/core/edit.zig +++ b/core/edit.zig @@ -205,7 +205,7 @@ pub fn paneText(p: *Pardes, pane: *Pane) ![]u8 { const from = modal.lineStartOffset(tag, pane.tag_top); const cut = modal.lineStartOffset(tag, pane.tag_top + pane.tag_rows); const shown = if (cut < tag.len) tag[from .. cut - 1] else tag[from..]; - return std.fmt.allocPrint(arena, "{s}\n{s}", .{ shown, try body_layer.bodyText(arena, pane) }); + return std.fmt.allocPrint(arena, "{s}\n{s}", .{ shown, try body_layer.bodyText(p.settings.tab, arena, pane) }); } pub fn pointerSourceLine(pane: *Pane, terminal_lines: []const []const u8, row: i32) []const u8 { @@ -223,7 +223,7 @@ pub fn capturePointerSelection(p: *Pardes, pane: *Pane, slot: usize) !void { pane.clearPointerSelection(slot); // Refresh the source map before translating the rendered rectangle. const raw = pane.isTerminal() and pane.body.mode == .tty; - const body = try body_layer.bodyText(p.scratch.allocator(), pane); + const body = try body_layer.bodyText(p.settings.tab, p.scratch.allocator(), pane); const terminal_lines = if (pane.file == null and !raw) try terminalLines(p, pane) else &.{}; const first = @max(0, @min(gesture.r0, gesture.r1) - pane.tag_rows); const logical_rows = if (pane.body_rows > 0) pane.body_rows else pane.rows; @@ -240,29 +240,29 @@ pub fn capturePointerSelection(p: *Pardes, pane: *Pane, slot: usize) !void { const cols = sweepCols(gesture, visible + @as(i32, pane.tag_rows)).?; const left: i32 = if (cols.first) @max(cols.lo, prefix) else prefix; const right: i32 = cols.hi orelse std.math.maxInt(i32) / 2; - var source = pane.wrapAt(visible); + var source = pane.wrapAt(p.settings.tab, visible); if (raw) source = .{ .line = @as(i32, @intCast(panes.Term.grid(pane.terminal).offset)) + visible, .at = 0 }; const line = if (raw) modal.lineSlice(body, @intCast(visible)) else pointerSourceLine(pane, terminal_lines, source.line); - var next = pane.wrapAt(visible + 1); + var next = pane.wrapAt(p.settings.tab, visible + 1); if (raw) next = .{ .line = source.line + 1, .at = 0 }; const end = if (next.line == source.line) @min(line.len, @as(usize, @intCast(@max(0, next.at)))) else line.len; const start: usize = @intCast(@max(0, source.at)); // A file row through its table pads (File.rowPads), as it is drawn. const lo: usize = @min(end, if (pane.file != null and !raw) - @as(usize, @intCast(panes.File.byteAtRowDisplay(pane, source.line, source.at, @max(0, left - prefix - source.pad)))) + @as(usize, @intCast(panes.File.byteAtRowDisplay(p.settings.tab, pane, source.line, source.at, @max(0, left - prefix - source.pad)))) else - panes.File.byteAtDisplayFrom(line, start, @intCast(@max(0, left - prefix - source.pad)))); + panes.File.byteAtDisplayFrom(p.settings.tab, line, start, @intCast(@max(0, left - prefix - source.pad)))); const at: usize = @min(end, if (pane.file != null and !raw) - @as(usize, @intCast(panes.File.byteAtRowDisplay(pane, source.line, source.at, @max(0, right - prefix - source.pad)))) + @as(usize, @intCast(panes.File.byteAtRowDisplay(p.settings.tab, pane, source.line, source.at, @max(0, right - prefix - source.pad)))) else - panes.File.byteAtDisplayFrom(line, start, @intCast(@max(0, right - prefix - source.pad)))); + panes.File.byteAtDisplayFrom(p.settings.tab, line, start, @intCast(@max(0, right - prefix - source.pad)))); row.* = .{ .row = source.line, .lo = lo, .hi = if (right < prefix) lo else if (cols.hi == null) end else @min(end, modal.nextGrapheme(line, at)), .to_edge = cols.hi == null, .raw_terminal = raw, - .prompt_bytes = if (raw) panes.Term.promptPrefix(pane.terminal, source.line, line) else 0, + .prompt_bytes = if (raw) panes.Term.promptPrefix(p.settings.tab, pane.terminal, source.line, line) else 0, }; } pane.next_pointer_selection += 1; @@ -316,9 +316,9 @@ pub fn selectionText(p: *Pardes, pane: *Pane, sl: Pane.Sel) ![]const u8 { // A body row starts after its line numbers, wherever the press was. const gutter: i32 = if (pane.file != null and v >= pane.tag_rows) panes.File.gutterWidth(pane) else 0; const lo: usize = @intCast(if (cols.first) @max(cols.lo, gutter) else gutter); - const b0 = @min(panes.File.renderedLineByteCol(pane, v, line, lo), line.len); + const b0 = @min(panes.File.renderedLineByteCol(p.settings.tab, pane, v, line, lo), line.len); const b1 = if (cols.hi) |hi| - @max(b0, modal.nextGrapheme(line, @min(panes.File.renderedLineByteCol(pane, v, line, @intCast(hi)), line.len))) + @max(b0, modal.nextGrapheme(line, @min(panes.File.renderedLineByteCol(p.settings.tab, pane, v, line, @intCast(hi)), line.len))) else line.len; try out.appendSlice(arena, line[b0..b1]); @@ -373,7 +373,7 @@ pub fn exitInsert(e: Editor, t: *Text) void { const head = if (r.head > r.anchor) @max(from, modal.prevGrapheme(text, to)) else to; r.* = .{ .anchor = from, .head = head }; } - t.setRanges(text, rs[0..got.n], &.{}, got.pri, expl); + t.setRanges(e.tab, text, rs[0..got.n], &.{}, got.pri, expl); } pub fn paneCursorLines(e: Editor, t: *Text) Error![]const []const u8 { @@ -393,12 +393,12 @@ pub fn paneCursorLines(e: Editor, t: *Text) Error![]const []const u8 { pub fn paneByteAtDisplay(e: Editor, t: *Text, row: i32, from_raw: i32, display_col: i32) i32 { if (t.what == .body) if (t.pane()) |pane| if (pane.file != null) - return panes.File.byteAtRowDisplay(pane, row, from_raw, display_col); + return panes.File.byteAtRowDisplay(e.tab, pane, row, from_raw, display_col); const lines = paneCursorLines(e, t) catch return @max(0, from_raw + display_col); const local = row; if (local < 0 or @as(usize, @intCast(local)) >= lines.len) return @max(0, from_raw + display_col); - return @intCast(panes.File.byteAtDisplayFrom( + return @intCast(panes.File.byteAtDisplayFrom(e.tab, lines[@intCast(local)], @intCast(@max(0, from_raw)), @intCast(@max(0, display_col)), @@ -908,13 +908,13 @@ pub fn enterInsert(e: Editor, t: *Text, where: InsertAt, cnt: usize) Error!void const o = modal.offsetAt(t2, .{ .row = @intCast(@max(0, t.cur_row) + @as(i32, @intCast(k))), .col = ind.len }); rs[k] = .{ .anchor = o, .head = o }; } - t.setRanges(t2, rs[0..m], &.{}, 0, false); + t.setRanges(e.tab, t2, rs[0..m], &.{}, 0, false); } }, } t.mode = .insert; t.normal.clear(); - t.show(); + t.show(e.tab); } pub fn handleInsert(e: Editor, t: *Text, key: Key) void { @@ -1031,12 +1031,12 @@ fn insertEdit(e: Editor, t: *Text, key: Key) Error!void { const nc = switch (key.cp) { Key.left => modal.charLeft(lines, cur0), Key.right => modal.charRight(lines, cur0), - Key.up => Text.insertVerticalCursor(lines, cur0, false), - Key.down => Text.insertVerticalCursor(lines, cur0, true), + Key.up => Text.insertVerticalCursor(e.tab, lines, cur0, false), + Key.down => Text.insertVerticalCursor(e.tab, lines, cur0, true), else => cur0, }; t.fromModalCursor(nc); - t.show(); + t.show(e.tab); return; }, Key.page_up, Key.page_down => { @@ -1046,13 +1046,13 @@ fn insertEdit(e: Editor, t: *Text, key: Key) Error!void { const range = t.primaryRange(flat, 0); if (t.what != .body) return; const step: i32 = @intCast(@max(1, (t.pane() orelse return).rows)); - t.scrollViewMove(flat, range, if (key.cp == Key.page_down) step else -step); + t.scrollViewMove(e.tab, flat, range, if (key.cp == Key.page_down) step else -step); return; }, Key.home => { t.cur_col = 0; t.cur_pinned = true; - t.show(); + t.show(e.tab); return; }, Key.end => { @@ -1061,7 +1061,7 @@ fn insertEdit(e: Editor, t: *Text, key: Key) Error!void { const cur0 = t.toModalCursor(); t.cur_col = @intCast(panes.File.textLine(t, text, cur0.row).len); t.cur_pinned = true; - t.show(); + t.show(e.tab); return; }, else => {}, @@ -1088,7 +1088,7 @@ fn insertEdit(e: Editor, t: *Text, key: Key) Error!void { t.cur_row = @as(i32, @intCast(end.row)) + eb.row0; t.cur_col = @intCast(end.col); t.cur_pinned = true; - t.show(); + t.show(e.tab); return; } // helix insert-mode kills (word/line; deleteSpan is exclusive) @@ -1108,7 +1108,7 @@ fn insertEdit(e: Editor, t: *Text, key: Key) Error!void { t.cur_row = @as(i32, @intCast(fc.row)) + e2.row0; t.cur_col = @intCast(fc.col); t.cur_pinned = true; - t.show(); + t.show(e.tab); return; } if (hit(key, config.delete_word_forward)) { @@ -1131,7 +1131,7 @@ fn insertEdit(e: Editor, t: *Text, key: Key) Error!void { try setEditTextEnd(e, t, new, .{ .row = c.row, .col = 0 }); t.cur_col = 0; t.cur_pinned = true; - t.show(); + t.show(e.tab); return; } if (hit(key, config.kill_to_line_end)) { @@ -1153,7 +1153,7 @@ fn insertEdit(e: Editor, t: *Text, key: Key) Error!void { try setEditTextEnd(e, t, new, .{ .row = c.row + 1, .col = 0 }); t.cur_row += 1; t.cur_pinned = true; - t.show(); + t.show(e.tab); return; } // The tree's indent where the file's grammar has an indent @@ -1180,7 +1180,7 @@ fn insertEdit(e: Editor, t: *Text, key: Key) Error!void { t.cur_row += 1; t.cur_col = @intCast(mid.len); t.cur_pinned = true; - t.show(); + t.show(e.tab); }, Key.backspace => { if (t.cur_col > 0) { @@ -1213,7 +1213,7 @@ fn insertEdit(e: Editor, t: *Text, key: Key) Error!void { } t.cur_col = @intCast(prev); t.cur_pinned = true; - t.show(); + t.show(e.tab); return; } // at col 0: eat the newline above (join up) — a terminal grows @@ -1228,7 +1228,7 @@ fn insertEdit(e: Editor, t: *Text, key: Key) Error!void { t.cur_row -= 1; t.cur_col = @intCast(prevlen); t.cur_pinned = true; - t.show(); + t.show(e.tab); }, Key.delete => { // delete forward; at line end eat the newline (join), which on @@ -1285,7 +1285,7 @@ pub fn insertTab(e: Editor, t: *Text) Error!void { try setEditTextEnd(e, t, new, .{ .row = c.row, .col = c.col + pad }); t.cur_col += @intCast(pad); t.cur_pinned = true; - t.show(); + t.show(e.tab); } const Bounds = struct { lo_row: i32, lo_col: i32, hi_row: i32, hi_col: i32 }; @@ -1325,7 +1325,7 @@ pub fn normalDelete(e: Editor, t: *Text, yank: bool) Error!void { try setEditText(e, t, new); t.cur_row = b.lo_row; t.cur_col = b.lo_col; - t.clampCursor(new, eb.row0); + t.clampCursor(e.tab, new, eb.row0); } pub fn normalYank(e: Editor, t: *Text) Error!void { @@ -1399,7 +1399,7 @@ pub fn pasteText(e: Editor, t: *Text, y0: []const u8, before: bool, count: usize } } t.cur_pinned = true; - t.show(); + t.show(e.tab); } pub fn normalChange(e: Editor, t: *Text) Error!void { @@ -1427,7 +1427,7 @@ pub fn normalChange(e: Editor, t: *Text) Error!void { t.cur_pinned = true; t.mode = .insert; t.normal.clear(); - t.show(); + t.show(e.tab); return; } try setYank(e, try vselText(e, t)); @@ -1436,7 +1436,7 @@ pub fn normalChange(e: Editor, t: *Text) Error!void { try setEditText(e, t, new); t.cur_row = b.lo_row; t.cur_col = b.lo_col; - t.clampCursor(new, eb.row0); + t.clampCursor(e.tab, new, eb.row0); t.mode = .insert; t.normal.clear(); return; @@ -1489,7 +1489,7 @@ fn setEditCells(e: Editor, t: *Text, new: []u8, row0: i32, cells: []const Text.C const text = try flatSurface(e, t); var rs: [Text.max_selections]modal.Selection = undefined; for (sels[0..cells.len], rs[0..cells.len]) |s, *r| r.* = Text.cellRange(text, s.arow, s.acol, s.row, s.col); - t.setRanges(text, rs[0..cells.len], &.{}, pri, expl); + t.setRanges(e.tab, text, rs[0..cells.len], &.{}, pri, expl); } /// `r<ch>`: overwrite the selection (or the cursor char) with ch — @@ -1515,7 +1515,7 @@ pub fn normalReplaceChar(e: Editor, t: *Text, ch: u21) Error!void { .{ .anchor = end, .head = lo } else .{ .anchor = lo, .head = end }; - t.setRange(new, eb.row0, mapped, t.vsel.explicit); + t.setRange(e.tab, new, eb.row0, mapped, t.vsel.explicit); } /// `R`: replace the selection (or the cursor char) with the DEFAULT @@ -1538,7 +1538,7 @@ fn replaceWithText(e: Editor, t: *Text, y: []const u8) Error!void { const new = try modal.spliceAlloc(e.gpa, eb.text, lo, @max(r.anchor, r.head), y); try setEditText(e, t, new); const end = lo + y.len; - t.setRange(new, eb.row0, if (r.head < r.anchor) .{ .anchor = end, .head = lo } else .{ .anchor = lo, .head = end }, false); + t.setRange(e.tab, new, eb.row0, if (r.head < r.anchor) .{ .anchor = end, .head = lo } else .{ .anchor = lo, .head = end }, false); } /// `~` / `` ` `` / ``Alt-` ``: case-map the selection (or the cursor char), @@ -1711,7 +1711,7 @@ pub fn normalAlign(e: Editor, t: *Text) Error!void { row[i] = modal.lineAtOffset(text, r.head); if (modal.lineAtOffset(text, r.anchor) != row[i]) return; const ls = modal.lineStartOffset(text, row[i]); - col[i] = panes.File.rawDisplayCol(text[ls..modal.lineEndOffset(text, row[i])], r.head - ls); + col[i] = panes.File.rawDisplayCol(e.tab, text[ls..modal.lineEndOffset(text, row[i])], r.head - ls); if (row[i] != line) { line = row[i]; k = 0; @@ -1819,7 +1819,7 @@ pub fn normalIndent(e: Editor, t: *Text, cnt: usize, add: bool) Error!void { } t.cur_pinned = true; t.sticky_col = -1; - t.show(); + t.show(e.tab); } pub fn normalToggleComment(e: Editor, t: *Text) Error!void { @@ -1912,7 +1912,7 @@ pub fn normalAdjustNumber(e: Editor, t: *Text, delta: i64) Error!void { t.select = false; const new = try modal.spliceAlloc(e.gpa, eb.text, lo, hi, rep); try setEditText(e, t, new); - t.setRange(new, eb.row0, .{ .anchor = lo, .head = lo + rep.len }, false); + t.setRange(e.tab, new, eb.row0, .{ .anchor = lo, .head = lo + rep.len }, false); } /// `]Space` / `[Space`: add blank lines below/above, the cursor staying @@ -1937,7 +1937,7 @@ pub fn addNewline(e: Editor, t: *Text, below: bool, cnt: usize) Error!void { if (t.vsel.active) t.vsel.row += n; } t.cur_pinned = true; - t.show(); + t.show(e.tab); } /// pair mapping for m-mode: either bracket names the pair; anything else @@ -1968,16 +1968,16 @@ pub fn textobjectSelect(e: Editor, t: *Text, text: []const u8, obj: u21, around: if (object) |o| { const tree = normal.nodeTree(e, t, text) orelse return; const s = syntax.objectAt(tree.path, tree.root, text, o, around, modal.selectionCursor(text, range)) orelse return; - return t.setRange(text, 0, .{ .anchor = s.from, .head = s.to }, false); + return t.setRange(e.tab, text, 0, .{ .anchor = s.from, .head = s.to }, false); } switch (obj) { 'w', 'W' => { const r = modal.selectWord(text, range, around, obj == 'W'); - return t.setRange(text, 0, r, false); + return t.setRange(e.tab, text, 0, r, false); }, 'p' => { const r = modal.selectParagraph(text, range, around, 1); - return t.setRange(text, 0, r, false); + return t.setRange(e.tab, text, 0, r, false); }, else => {}, } @@ -2000,7 +2000,7 @@ pub fn textobjectSelect(e: Editor, t: *Text, text: []const u8, obj: u21, around: a = modal.nextGrapheme(text, a); head = modal.prevGrapheme(text, head); } - t.setRange(text, 0, .{ .anchor = a, .head = head }, false); + t.setRange(e.tab, text, 0, .{ .anchor = a, .head = head }, false); } /// `ms<ch>`: wrap the selection (or the cursor char) in a pair; the wrap @@ -2018,7 +2018,7 @@ pub fn surroundAdd(e: Editor, t: *Text, ch: u21) Error!void { const new = try sam.apply(e.gpa, eb.text, &.{ .{ .q0 = @intCast(lo), .q1 = @intCast(lo), .text = &open }, .{ .q0 = @intCast(hi), .q1 = @intCast(hi), .text = &close } }); try setEditText(e, t, new); // the wrapped range keeps the direction it had (helix with_direction) - t.setRange(new, eb.row0, if (r.head < r.anchor) .{ .anchor = hi + 2, .head = lo } else .{ .anchor = lo, .head = hi + 2 }, false); + t.setRange(e.tab, new, eb.row0, if (r.head < r.anchor) .{ .anchor = hi + 2, .head = lo } else .{ .anchor = lo, .head = hi + 2 }, false); } /// `md<ch>`: delete the enclosing pair's chars; the cursor maps through @@ -2054,7 +2054,7 @@ pub fn surroundDelete(e: Editor, t: *Text, ch: u21) Error!void { t.cur_col = @intCast(cc.col); t.vsel.active = false; t.cur_pinned = true; - t.show(); + t.show(e.tab); } /// `mr<from><to>`: swap the enclosing <from> pair's chars for <to>'s @@ -2108,7 +2108,7 @@ pub fn undoStep(e: Editor, t: *Text, back: bool) error{OutOfMemory}!void { const to = (try pane.body.step(e.gpa, pane.ovl, back)) orelse return; if (pane.ovl) |o| e.gpa.free(o.text); pane.ovl = to.ovl; - pane.ensureCursorVisible(); + pane.ensureCursorVisible(e.tab); } /// Undo or redo an edit of a text's own characters; stepping back past its diff --git a/core/edit_cmd.zig b/core/edit_cmd.zig index f4b6096a..6cd7788d 100644 --- a/core/edit_cmd.zig +++ b/core/edit_cmd.zig @@ -416,7 +416,7 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void { panes.File.setContent(p, pf, new); } } - if (ops.len > 0 or f.moved) ninep_pane.setDot(pane, sam.moveDot(f.dot, ops)); + if (ops.len > 0 or f.moved) ninep_pane.setDot(p.settings.tab, pane, sam.moveDot(f.dot, ops)); if (f.renamed) ninep_pane.nameBuffer(p, f.id, f.name, false) catch |err| p.reportError(f.id, "Edit", err); } // What was printed, `>`'s output in its place among it. diff --git a/core/exec.zig b/core/exec.zig index 601d43dc..6804a22e 100644 --- a/core/exec.zig +++ b/core/exec.zig @@ -110,12 +110,12 @@ fn spanHas(r: i32, c: i32, ar: i32, ac: i32, br: i32, bc: i32) bool { /// anywhere else. pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_look: bool) PointerOperand { const visible = clicked.r0 - @as(i32, pane.tag_rows); - const wrapped = pane.wrapAt(visible); + const wrapped = pane.wrapAt(p.settings.tab, visible); const raw = pane.isTerminal() and pane.body.mode == .tty and clicked.r0 >= pane.tag_rows; const row = if (raw) @as(i32, @intCast(panes.Term.grid(pane.terminal).offset)) + visible else wrapped.line; - const raw_line = if (raw) modal.lineSlice(body_layer.bodyText(p.scratch.allocator(), pane) catch "", @intCast(@max(0, visible))) else ""; + const raw_line = if (raw) modal.lineSlice(body_layer.bodyText(p.settings.tab, p.scratch.allocator(), pane) catch "", @intCast(@max(0, visible))) else ""; const col = if (raw) - @as(i32, @intCast(panes.File.rawAtDisplay(raw_line, @intCast(@max(0, clicked.c0))))) + @as(i32, @intCast(panes.File.rawAtDisplay(p.settings.tab, raw_line, @intCast(@max(0, clicked.c0))))) else if (clicked.r0 >= pane.tag_rows) edit.paneByteAtDisplay( p.editor(), @@ -144,7 +144,7 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l lo -|= span.prompt_bytes; hi -|= span.prompt_bytes; } else if (!span.raw_terminal and raw) { - const prefix = panes.Term.promptPrefix(pane.terminal, row, raw_line); + const prefix = panes.Term.promptPrefix(p.settings.tab, pane.terminal, row, raw_line); lo += prefix; hi += prefix; } @@ -186,11 +186,11 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l var expanded = clicked; if (pane.file != null) { result.file_word = .{ .row = row, .lo = 0, .hi = hi }; - expanded = fileWordCells(pane, clicked, row, 0, hi) orelse return result; + expanded = fileWordCells(p.settings.tab, pane, clicked, row, 0, hi) orelse return result; } else { const shown = if (raw) raw_line else got.line; expanded.c0 = 0; - expanded.c1 = @as(i32, @intCast(panes.File.rawDisplayCol(shown, shown.len))) - 1; + expanded.c1 = @as(i32, @intCast(panes.File.rawDisplayCol(p.settings.tab, shown, shown.len))) - 1; } result.preview = expanded; result.expanded = expanded; @@ -212,7 +212,7 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l const hi = std.math.cast(i32, b.hi) orelse return result; result.text = line[b.lo..b.hi]; result.file_word = .{ .row = row, .lo = lo, .hi = hi }; - const expanded = fileWordCells(pane, clicked, row, lo, hi) orelse clicked; + const expanded = fileWordCells(p.settings.tab, pane, clicked, row, lo, hi) orelse clicked; result.preview = expanded; result.expanded = expanded; return result; @@ -228,15 +228,15 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l /// The cells bytes `lo..hi` of a file pane's line `row` take on screen, /// soft-wrapped or not, as `clicked` reshaped; null when scrolled off. -fn fileWordCells(pane: *Pane, clicked: Pane.Sel, row: i32, lo: i32, hi: i32) ?Pane.Sel { - const first = pane.wrapRow(row, lo); - const last = pane.wrapRow(row, hi - 1); +fn fileWordCells(tab: u16, pane: *Pane, clicked: Pane.Sel, row: i32, lo: i32, hi: i32) ?Pane.Sel { + const first = pane.wrapRow(tab, row, lo); + const last = pane.wrapRow(tab, row, hi - 1); if (first.row < 0 or last.row < 0) return null; var cells = clicked; cells.r0 = first.row + @as(i32, pane.tag_rows); - cells.c0 = @as(i32, panes.File.gutterWidth(pane)) + first.pad + panes.File.displayOffset(pane, row, first.at, lo); + cells.c0 = @as(i32, panes.File.gutterWidth(pane)) + first.pad + panes.File.displayOffset(tab, pane, row, first.at, lo); cells.r1 = last.row + @as(i32, pane.tag_rows); - cells.c1 = @as(i32, panes.File.gutterWidth(pane)) + last.pad + panes.File.displayEndOffset(pane, row, last.at, hi - 1); + cells.c1 = @as(i32, panes.File.gutterWidth(pane)) + last.pad + panes.File.displayEndOffset(tab, pane, row, last.at, hi - 1); return cells; } @@ -1038,8 +1038,6 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[] } else if (!p.settings.apply(setting, arg)) { var said: pardes.Kind.Buf(96) = .{}; p.reportFailure(v.active, said.print("{s}{s}: takes {s}", .{ setting.word, if (tag == .tab) ": invalid tab width" else "", comptime config.Runtime.takes(tag).? })); - } else if (tag == .tab) { - config.tab_now = p.settings.tab; }, // Said with what it takes: its words, its range. else => if (!p.settings.apply(setting, arg)) { @@ -1124,7 +1122,7 @@ test "the acme chords act once per selection, not once on the primary" { .{ .anchor = 0, .head = 6 }, .{ .anchor = 7, .head = 13 }, }; - pane.body.setRanges(pane.file.?.content, &ranges, &.{}, 0, true); + pane.body.setRanges(config.tab_width, pane.file.?.content, &ranges, &.{}, 0, true); try std.testing.expectEqual(@as(u16, 1), pane.body.nsel); const before = p.view().ncol; diff --git a/core/hunks.zig b/core/hunks.zig index 186ba928..d3a8f5a7 100644 --- a/core/hunks.zig +++ b/core/hunks.zig @@ -37,6 +37,8 @@ pub const Ctx = struct { /// A declaration above a hunk gets its `path:line` row too /// (LocationsConfig's tslocations). tslocations: bool, + /// A tab's width in cells (the core's `settings.tab`). + tab: u16, }; /// A file's text, and its path as `dir` and the path named resolve. @@ -346,7 +348,7 @@ fn flush(ctx: *const Ctx, out: *Out, hunk: *Hunk, memo: *SourceMemo, dir: []cons while (i < lines.len and lines[i].kind == .removed) i += 1; const plus_start = i; while (i < lines.len and lines[i].kind == .added) i += 1; - try inferEdits(arena, lines[minus_start..plus_start], lines[plus_start..i]); + try inferEdits(ctx.tab, arena, lines[minus_start..plus_start], lines[plus_start..i]); } // Each line behind its marker, `+`, `-` or a blank, as the diff @@ -390,7 +392,7 @@ const pair_scratch_bytes = 8 << 20; /// Pair each removed line with the first added line after the last one /// paired that is near enough to it, in order, and emphasise in both the /// tokens one has and the other has not. -fn inferEdits(arena: std.mem.Allocator, minus: []HunkLine, plus: []HunkLine) !void { +fn inferEdits(tab: u16, arena: std.mem.Allocator, minus: []HunkLine, plus: []HunkLine) !void { if (minus.len == 0 or plus.len == 0 or minus.len > max_run or plus.len > max_run) return; const plus_tokens = try arena.alloc([]const []const u8, plus.len); for (plus, plus_tokens) |line, *tokens| tokens.* = try tokenize(arena, line.code); @@ -408,7 +410,7 @@ fn inferEdits(arena: std.mem.Allocator, minus: []HunkLine, plus: []HunkLine) !vo scratch.reset(); const pair = scratch.allocator(); var alignment = Alignment.init(pair, m_tokens, p_tokens) catch continue; - const marks = annotate(pair, &alignment, m.code, plus[j].code) catch continue; + const marks = annotate(tab, pair, &alignment, m.code, plus[j].code) catch continue; if (marks.distance > max_line_distance) continue; for (marks.minus) |r| for (m.styles[r[0]..r[1]]) |*b| { b.* |= syntax.ground_emph; @@ -534,7 +536,7 @@ const Marks = struct { /// what each deleted and inserted, and a run of blanks between two changes /// with them; the distance is the changed width over the whole width (a /// kept section counting on both lines). -fn annotate(arena: std.mem.Allocator, a: *const Alignment, minus_line: []const u8, plus_line: []const u8) !Marks { +fn annotate(tab: u16, arena: std.mem.Allocator, a: *const Alignment, minus_line: []const u8, plus_line: []const u8) !Marks { var minus: std.ArrayList([2]usize) = .empty; var plus: std.ArrayList([2]usize) = .empty; var x_off: usize = 0; @@ -560,7 +562,7 @@ fn annotate(arena: std.mem.Allocator, a: *const Alignment, minus_line: []const u switch (op) { .deletion => { const r = Take.section(a.x, &x_off, &m_byte, n, minus_line); - const w = trimmedWidth(minus_line[r[0]..r[1]]); + const w = trimmedWidth(tab, minus_line[r[0]..r[1]]); numer += w; denom += w; try minus.append(arena, r); @@ -569,7 +571,7 @@ fn annotate(arena: std.mem.Allocator, a: *const Alignment, minus_line: []const u .noop => { const r = Take.section(a.x, &x_off, &m_byte, n, minus_line); const section = minus_line[r[0]..r[1]]; - denom += 2 * trimmedWidth(section); + denom += 2 * trimmedWidth(tab, section); const is_space = std.mem.trim(u8, section, " \t").len == 0; const coalesce = is_space and ((minus_prev == .deletion and plus_prev == .insertion and @@ -583,7 +585,7 @@ fn annotate(arena: std.mem.Allocator, a: *const Alignment, minus_line: []const u }, .insertion => { const r = Take.section(a.y, &y_off, &p_byte, n, plus_line); - const w = trimmedWidth(plus_line[r[0]..r[1]]); + const w = trimmedWidth(tab, plus_line[r[0]..r[1]]); numer += w; denom += w; try plus.append(arena, r); @@ -595,8 +597,8 @@ fn annotate(arena: std.mem.Allocator, a: *const Alignment, minus_line: []const u return .{ .minus = minus.items, .plus = plus.items, .distance = distance }; } -fn trimmedWidth(section: []const u8) usize { - return @import("File.zig").displayWidth(std.mem.trim(u8, section, " \t")); +fn trimmedWidth(tab: u16, section: []const u8) usize { + return @import("File.zig").displayWidth(tab, std.mem.trim(u8, section, " \t")); } // ---- the +Diff in the editor ---- @@ -734,6 +736,7 @@ pub fn openDiff(p: *Pardes, id: usize, path: []const u8, content: []const u8) !u .declarations = Read.declarations, .host = p, .tslocations = p.locations_config.tslocations, + .tab = p.settings.tab, }; const root = sourceRoot(&ctx, dir, content); const result = try format(&ctx, root, content); @@ -793,7 +796,7 @@ const TestCtx = struct { fn init(t: *TestCtx) void { t.arena_state = .init(testing.allocator); - t.ctx = .{ .gpa = testing.allocator, .arena = t.arena_state.allocator(), .source = source, .declarations = declarations, .host = t, .tslocations = true }; + t.ctx = .{ .gpa = testing.allocator, .arena = t.arena_state.allocator(), .source = source, .declarations = declarations, .host = t, .tslocations = true, .tab = @import("config.zig").tab_width }; syntax.start(testing.allocator); } @@ -819,7 +822,7 @@ fn emphasised(line: HunkLine) ![]const u8 { return out.toOwnedSlice(testing.allocator); } -fn expectEmphasis(minus: []const u8, plus: []const u8, want_minus: []const u8, want_plus: []const u8) !void { +fn expectEmphasis(tab: u16, minus: []const u8, plus: []const u8, want_minus: []const u8, want_plus: []const u8) !void { var arena_state: std.heap.ArenaAllocator = .init(testing.allocator); defer arena_state.deinit(); const arena = arena_state.allocator(); @@ -827,7 +830,7 @@ fn expectEmphasis(minus: []const u8, plus: []const u8, want_minus: []const u8, w var p = [_]HunkLine{.{ .kind = .added, .code = plus, .styles = try arena.alloc(u8, plus.len), .old = 2, .new = 1 }}; @memset(m[0].styles, 0); @memset(p[0].styles, 0); - try inferEdits(arena, &m, &p); + try inferEdits(tab, arena, &m, &p); const got_minus = try emphasised(m[0]); defer testing.allocator.free(got_minus); const got_plus = try emphasised(p[0]); @@ -837,16 +840,16 @@ fn expectEmphasis(minus: []const u8, plus: []const u8, want_minus: []const u8, w } test "delta's emphasis: the word a line changed, in both lines" { - try expectEmphasis(" let x = foo(1);", " let x = bar(1);", "............foo....", "............bar...."); - try expectEmphasis("a b c", "a x c", "..b..", "..x.."); + try expectEmphasis(@import("config.zig").tab_width, " let x = foo(1);", " let x = bar(1);", "............foo....", "............bar...."); + try expectEmphasis(@import("config.zig").tab_width, "a b c", "a x c", "..b..", "..x.."); } test "delta's emphasis: lines too far apart are no change of one another" { - try expectEmphasis("completely different text", "nothing alike here at all", ".........................", "........................."); + try expectEmphasis(@import("config.zig").tab_width, "completely different text", "nothing alike here at all", ".........................", "........................."); } test "delta's emphasis: a word added keeps the rest plain" { - try expectEmphasis("fn run(a: u32)", "fn run(a: u32, b: u32)", "..............", "............., b: u32."); + try expectEmphasis(@import("config.zig").tab_width, "fn run(a: u32)", "fn run(a: u32, b: u32)", "..............", "............., b: u32."); } test "delta's alignment: kitten to sitting, as align.rs has it" { diff --git a/core/layout.zig b/core/layout.zig index 6f74025d..0c17191c 100644 --- a/core/layout.zig +++ b/core/layout.zig @@ -596,7 +596,7 @@ pub fn wantedTagRows(p: *Pardes, id: usize) u16 { const wa = wrap_fba.allocator(); const prefix = tagline.prefixIn(p, wa, pane) catch return pane.tag_rows; const whole = std.mem.concat(wa, u8, &.{ prefix, tagline.curTail(pane) }) catch return pane.tag_rows; - const shown = tagline.wrapTag(wa, whole, tagline.tagWidth(p, id)) catch return pane.tag_rows; + const shown = tagline.wrapTag(p.settings.tab, wa, whole, tagline.tagWidth(p, id)) catch return pane.tag_rows; return @intCast(@max(BOX_H, @min(shown.rows(), MAX_TAG_ROWS))); } diff --git a/core/lib_editor.zig b/core/lib_editor.zig index ee42a2cd..c459241a 100644 --- a/core/lib_editor.zig +++ b/core/lib_editor.zig @@ -240,6 +240,7 @@ const Live = struct { .multi_index = &l.multi_index, .multi_count = &l.multi_count, .retired_edit = &l.retired_edit, + .tab = @import("config.zig").tab_width, .p = {}, .failed = &l.failed, .syntax = l.syntax, diff --git a/core/locations.zig b/core/locations.zig index da8179d0..6972647e 100644 --- a/core/locations.zig +++ b/core/locations.zig @@ -234,7 +234,7 @@ pub fn parseRows(arena: std.mem.Allocator, text: []const u8) error{ OutOfMemory, /// Compare native producer rows with an already formatted, context-free view. /// Identical refreshes retain allocations, syntax and selection state. -pub fn sameInput(input: []const u8, rendered: []const u8, rows: []const Row, layout: Config.Layout) bool { +pub fn sameInput(tab: u16, input: []const u8, rendered: []const u8, rows: []const Row, layout: Config.Layout) bool { if (rows.len == 0) return std.mem.eql(u8, input, rendered); var raw_lines = std.mem.splitScalar(u8, input, '\n'); var shown_lines = std.mem.splitScalar(u8, rendered, '\n'); @@ -249,7 +249,7 @@ pub fn sameInput(input: []const u8, rendered: []const u8, rows: []const Row, lay for (0..alignment_entries) |_| { const line = chunk.next() orelse break; const target = parseRaw(line); - width = @max(width, pardes.panes.File.displayWidth(line[0..target.end])); + width = @max(width, pardes.panes.File.displayWidth(tab, line[0..target.end])); } } const raw = raw_lines.next() orelse return false; @@ -272,7 +272,7 @@ pub fn sameInput(input: []const u8, rendered: []const u8, rows: []const Row, lay // let the identical-input shortcut retain that layout when rerun. if (row.code_start <= row.location_end) return false; const padding = shown[row.location_end..row.code_start]; - if (padding.len != width - pardes.panes.File.displayWidth(raw[0..target.end]) + 1 or + if (padding.len != width - pardes.panes.File.displayWidth(tab, raw[0..target.end]) + 1 or padding[padding.len - 1] != '\t') return false; for (padding[0 .. padding.len - 1]) |byte| if (byte != ' ') return false; index += 1; @@ -538,8 +538,8 @@ pub fn formatCallstack(p: *pardes.Pardes, dir: []const u8, input: []const u8) !R var guide_buf: [1024]u8 = undefined; const guide = treeContinuation(line, &guide_buf, std.math.maxInt(usize)); try out.writer.writeAll(guide); - const width = pardes.panes.File.displayWidth(line[0..prefix.end]); - try out.writer.splatByteAll(' ', width -| pardes.panes.File.displayWidth(guide)); + const width = pardes.panes.File.displayWidth(p.settings.tab, line[0..prefix.end]); + try out.writer.splatByteAll(' ', width -| pardes.panes.File.displayWidth(p.settings.tab, guide)); const code_start = out.written().len - start; const trim = @min(source_indent, code_line.len - std.mem.trimStart(u8, code_line, " \t").len); try out.writer.writeAll(code_line[trim..]); @@ -691,7 +691,7 @@ pub fn format(p: *pardes.Pardes, dir: []const u8, input: []const u8, anchor: ?us while (first < pending.items.len) { const end = alignmentEnd(pending.items, first); var width: usize = 0; - for (pending.items[first..end]) |row| width = @max(width, labelWidth(row)); + for (pending.items[first..end]) |row| width = @max(width, labelWidth(p.settings.tab, row)); for (pending.items[first..end], first..) |row, index| { const before = out.written().len; const context = row.original == null; @@ -701,7 +701,7 @@ pub fn format(p: *pardes.Pardes, dir: []const u8, input: []const u8, anchor: ?us try out.writer.writeByte(' '); try out.writer.splatByteAll('*', row.depth); } - try out.writer.splatByteAll(' ', width - labelWidth(row)); + try out.writer.splatByteAll(' ', width - labelWidth(p.settings.tab, row)); try out.writer.writeByte('\t'); const code_start = out.written().len - before; try writeCode(&out.writer, pending.items, index); @@ -757,8 +757,8 @@ fn alignmentEnd(rows: []const Pending, first: usize) usize { return rows.len; } -fn labelWidth(row: Pending) usize { - return pardes.panes.File.displayWidth(row.label) + +fn labelWidth(tab: u16, row: Pending) usize { + return pardes.panes.File.displayWidth(tab, row.label) + @as(usize, if (row.depth > 0) row.depth + 1 else 0); } diff --git a/core/look.zig b/core/look.zig index 79880476..6ff1da66 100644 --- a/core/look.zig +++ b/core/look.zig @@ -251,10 +251,10 @@ pub fn expandedSel(p: *Pardes, pane: *Pane, at: Pane.Sel) ?Pane.Sel { while (it.next()) |line| : (v += 1) { if (v != sl.r0) continue; const display_col: usize = @intCast(@max(0, sl.c0)); - const col = panes.File.renderedLineByteCol(pane, v, line, display_col); + const col = panes.File.renderedLineByteCol(p.settings.tab, pane, v, line, display_col); const b = expandedWord(line, col) orelse return null; - sl.c0 = @intCast(panes.File.renderedLineDisplayCol(pane, v, line, b.lo)); - sl.c1 = @intCast(panes.File.renderedLineDisplayCol(pane, v, line, b.hi) - 1); + sl.c0 = @intCast(panes.File.renderedLineDisplayCol(p.settings.tab, pane, v, line, b.lo)); + sl.c1 = @intCast(panes.File.renderedLineDisplayCol(p.settings.tab, pane, v, line, b.hi) - 1); return sl; } return null; @@ -269,37 +269,37 @@ fn tagWordSel(p: *Pardes, pane: *Pane, at: Pane.Sel) ?Pane.Sel { const whole = tagline.tagText(p, arena, pane) catch return null; const row: usize = @as(usize, @intCast(at.r0)) + pane.tag_top; const shown_line = modal.lineSlice(shown.text, row); - const real = shown.toReal(modal.lineStartOffset(shown.text, row) + panes.File.rawAtDisplay(shown_line, @intCast(@max(0, at.c0)))); + const real = shown.toReal(modal.lineStartOffset(shown.text, row) + panes.File.rawAtDisplay(p.settings.tab, shown_line, @intCast(@max(0, at.c0)))); const start = if (std.mem.lastIndexOfScalar(u8, whole[0..@min(real, whole.len)], '\n')) |nl| nl + 1 else 0; const end = std.mem.indexOfScalarPos(u8, whole, start, '\n') orelse whole.len; const b = expandedWord(whole[start..end], real - start) orelse return null; - const lo = shownCell(shown.text, shown.fromReal(start + b.lo), pane.tag_top); - const hi = shownCell(shown.text, shown.fromReal(start + b.hi - 1), pane.tag_top); + const lo = shownCell(p.settings.tab, shown.text, shown.fromReal(start + b.lo), pane.tag_top); + const hi = shownCell(p.settings.tab, shown.text, shown.fromReal(start + b.hi - 1), pane.tag_top); return .{ .state = at.state, .r0 = lo.row, .c0 = lo.col, .r1 = hi.row, .c1 = hi.col }; } -fn shownCell(text: []const u8, off: usize, top: usize) struct { row: i32, col: i32 } { +fn shownCell(tab: u16, text: []const u8, off: usize, top: usize) struct { row: i32, col: i32 } { const before = text[0..@min(off, text.len)]; const row = std.mem.count(u8, before, "\n"); const line_start = if (std.mem.lastIndexOfScalar(u8, before, '\n')) |nl| nl + 1 else 0; return .{ .row = @as(i32, @intCast(row)) - @as(i32, @intCast(top)), - .col = @intCast(panes.File.rawDisplayCol(text[line_start..], off - line_start)), + .col = @intCast(panes.File.rawDisplayCol(tab, text[line_start..], off - line_start)), }; } /// the word under the modal cursor as a pane-local selection (paneText /// coords: row 0 is the tag; file panes carry the line-number prefix) pub fn cursorWordSel(p: *Pardes, pane: *Pane) Pane.Sel { - const w = pane.wrapRow(pane.body.cur_row, pane.body.cur_col); + const w = pane.wrapRow(p.settings.tab, pane.body.cur_row, pane.body.cur_col); const vrow = w.row + @as(i32, pane.tag_rows); const vcol = if (pane.file != null) - w.pad + panes.File.displayOffset(pane, pane.body.cur_row, w.at, pane.body.cur_col) + @as(i32, panes.File.gutterWidth(pane)) + w.pad + panes.File.displayOffset(p.settings.tab, pane, pane.body.cur_row, w.at, pane.body.cur_col) + @as(i32, panes.File.gutterWidth(pane)) else blk: { const lines = edit.paneCursorLines(p.editor(), &pane.body) catch break :blk pane.body.cur_col; const local = pane.body.cur_row; if (local < 0 or @as(usize, @intCast(local)) >= lines.len) break :blk pane.body.cur_col; - break :blk panes.File.lineDisplayOffset(lines[@intCast(local)], @intCast(@max(0, w.at)), @intCast(@max(0, pane.body.cur_col))); + break :blk panes.File.lineDisplayOffset(p.settings.tab, lines[@intCast(local)], @intCast(@max(0, w.at)), @intCast(@max(0, pane.body.cur_col))); }; return .{ .state = .done, .c0 = vcol, .c1 = vcol, .r0 = vrow, .r1 = vrow }; } @@ -645,7 +645,7 @@ fn landLookSpot(p: *Pardes, id: usize, pane: *Pane, spot: Pane.LookSpot) void { pane.look_at = spot; p.look_walk_owner = pane.serial; p.view().active = id; - pane.ensureCursorVisible(); + pane.ensureCursorVisible(p.settings.tab); } pub fn cancelLookHover(p: *Pardes) void { @@ -747,7 +747,7 @@ pub fn focusPaneLine(p: *Pardes, id: usize, at: Spot, landing: enum { center, ke pane.body.cur_col = if (at.col > 0) @intCast(at.col - 1) else 0; pane.body.cur_pinned = true; if (at.end_line != 0) return selectSpan(p, pane, at); - pane.ensureCursorVisible(); + pane.ensureCursorVisible(p.settings.tab); } fn selectSpan(p: *Pardes, pane: *Pane, at: Spot) void { @@ -757,7 +757,7 @@ fn selectSpan(p: *Pardes, pane: *Pane, at: Spot) void { const acol: i32 = @intCast(at.col -| 1); const ecol: i32 = if (at.end_col > 0) @intCast(at.end_col - 1) else std.math.maxInt(i32); const r = panes.Text.cellRange(text, @intCast(at.line -| 1), acol, @intCast(at.end_line -| 1), ecol); - pane.body.setRange(text, 0, r, true); + pane.body.setRange(p.settings.tab, text, 0, r, true); } fn openPaneTarget(p: *const Pardes, path: []const u8, at: Spot) ?Target { @@ -967,7 +967,7 @@ fn lookWord(p: *Pardes, id: usize, pane: *Pane, word: []const u8) void { return missed(p, id, "no match for \"{s}\"", .{missText(word, &cut)}); }); clearNavigationSelection(p, pane); - ninep_pane.setDot(pane, .{ .q0 = @intCast(at), .q1 = @intCast(at + word.len) }); + ninep_pane.setDot(p.settings.tab, pane, .{ .q0 = @intCast(at), .q1 = @intCast(at + word.len) }); p.view().active = id; } @@ -1131,7 +1131,7 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void { return missed(p, target, "{s}: {s}", .{ name, why }); } clearNavigationSelection(p, pane); - ninep_pane.setDot(pane, r); + ninep_pane.setDot(p.settings.tab, pane, r); v.active = target; } @@ -1396,7 +1396,7 @@ fn settleLine(p: *Pardes, id: usize, path: []const u8, at: Spot, before: usize, const start = modal.lineStartOffset(f.content, at.line - 1); const next = std.mem.indexOfScalarPos(u8, f.content, start, '\n'); const end = if (next) |i| i + 1 else f.content.len; - @import("ninep/pane.zig").setDot(shown, .{ .q0 = @intCast(start), .q1 = @intCast(end) }); + @import("ninep/pane.zig").setDot(p.settings.tab, shown, .{ .q0 = @intCast(start), .q1 = @intCast(end) }); } } @@ -2022,7 +2022,7 @@ test "Look ignores missing and out of bounds pane addresses" { defer p.deinit(); const pane = try p.setTestFile("alpha\nbravo\n"); for ([_][]const u8{ config.pane_addr ++ "15:2", config.pane_addr ++ "999999:2" }) |operand| { - pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 0, .head = 3 }, true); + pane.body.setRange(config.tab_width, pane.file.?.content, 0, .{ .anchor = 0, .head = 3 }, true); lookAt(p, 0, operand); try std.testing.expectEqual(@as(usize, 0), p.view().active); try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); @@ -2423,7 +2423,7 @@ test "a tag word looked at by a click and by Enter is one record to an event rea const shown_at = std.mem.lastIndexOf(u8, shown, "Del").?; const shown_row: u16 = @intCast(std.mem.count(u8, shown[0..shown_at], "\n")); const line_start = if (std.mem.lastIndexOfScalar(u8, shown[0..shown_at], '\n')) |nl| nl + 1 else 0; - const x = p.view().rects[0].x + TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(shown[line_start..shown_at]))) + 1; + const x = p.view().rects[0].x + TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(config.tab_width, shown[line_start..shown_at]))) + 1; const y = p.view().rects[0].y + shown_row; p.update(.{ .mouse = .{ .button = .right, .kind = .press, .col = x, .row = y } }); p.update(.{ .mouse = .{ .button = .right, .kind = .release, .col = x, .row = y } }); diff --git a/core/lsp/Ask.zig b/core/lsp/Ask.zig index 40ffaede..f00942b0 100644 --- a/core/lsp/Ask.zig +++ b/core/lsp/Ask.zig @@ -235,7 +235,7 @@ fn applyLspEdits(p: *Pardes, pane: *Pane, revision: u32, edits: []const LspEdit) pane.body.vsel.active = false; pane.body.select = false; pane.body.sticky_col = -1; - pane.ensureCursorVisible(); + pane.ensureCursorVisible(p.settings.tab); return true; } @@ -537,7 +537,7 @@ test "Callstack always opens and focuses its own pane, reusing it for another sy try std.testing.expect(std.mem.endsWith(u8, report.file.?.path, "/+Callstack")); try std.testing.expectEqual(@as(i32, 0), source.body.cur_row); const stale_selection = std.mem.indexOfScalar(u8, report.file.?.content, '\n').? + 1; - report.body.setRange(report.file.?.content, 0, .{ .anchor = stale_selection, .head = stale_selection + 6 }, true); + report.body.setRange(config.tab_width, report.file.?.content, 0, .{ .anchor = stale_selection, .head = stale_selection + 6 }, true); layout.toggleCollapse(p, 0); var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); diff --git a/core/mini.zig b/core/mini.zig index b4737f29..9a71bf4a 100644 --- a/core/mini.zig +++ b/core/mini.zig @@ -43,12 +43,12 @@ const Row = struct { ink: bool = false, color: u8 = 0, - fn dot(row: *Row, styles: []const u8) ?u8 { + fn dot(row: *Row, tab: u16, styles: []const u8) ?u8 { if (row.left == 0) { if (row.at == row.text.len) return null; const end = modal.nextGrapheme(row.text, row.at); const grapheme = row.text[row.at..end]; - row.left = File.graphemeDisplayWidth(grapheme); + row.left = File.graphemeDisplayWidth(tab, grapheme); // unreachable below: `generate` refuses a source that is no UTF-8 const n = std.unicode.utf8ByteSequenceLength(grapheme[0]) catch unreachable; const cp = std.unicode.utf8Decode(grapheme[0..n]) catch unreachable; @@ -61,7 +61,7 @@ const Row = struct { } }; -fn render(output: ?Result, source: []const u8, styles: []const u8) !usize { +fn render(tab: u16, output: ?Result, source: []const u8, styles: []const u8) !usize { if (source.len == 0) return 0; const end = source.len - @intFromBool(source[source.len - 1] == '\n'); var lines = std.mem.splitScalar(u8, source[0..end], '\n'); @@ -83,7 +83,7 @@ fn render(output: ?Result, source: []const u8, styles: []const u8) !usize { var counts: [5]u8 = @splat(0); for (&rows, 0..) |*row, y| { for (0..2) |x| { - if (row.dot(styles)) |color| { + if (row.dot(tab, styles)) |color| { mask |= @as(u8, 1) << bits[y][x]; counts[color] += 1; } @@ -122,18 +122,18 @@ fn render(output: ?Result, source: []const u8, styles: []const u8) !usize { return offset; } -pub fn generate(gpa: std.mem.Allocator, source: []const u8, styles: []const u8) !Result { +pub fn generate(tab: u16, gpa: std.mem.Allocator, source: []const u8, styles: []const u8) !Result { if (source.len > max_input_bytes) return error.MiniTooLarge; if (!std.unicode.utf8ValidateSlice(source)) return error.InvalidUtf8; if (styles.len != 0 and styles.len != source.len) return error.InvalidMiniColors; for (styles) |color| if (color > @backingInt(syntax.Syn.comment)) return error.InvalidMiniColors; - const len = try render(null, source, styles); + const len = try render(tab, null, source, styles); const content = try gpa.alloc(u8, len); errdefer gpa.free(content); const colors = try gpa.alloc(u8, len); errdefer gpa.free(colors); const result: Result = .{ .content = content, .colors = colors }; - const written = try render(result, source, styles); + const written = try render(tab, result, source, styles); std.debug.assert(written == len); return result; } @@ -151,7 +151,7 @@ pub fn open(p: *Pardes, id: usize, argument: []const u8) !void { defer p.gpa.free(input); const styles = try syntax.highlightFileRange(p.tree_sitter_gpa, source, input, 0, input.len); defer p.tree_sitter_gpa.free(styles); - const result = try generate(p.gpa, input, styles); + const result = try generate(p.settings.tab, p.gpa, input, styles); errdefer result.deinit(p.gpa); for (p.panes, 0..) |slot, i| { const pane = slot orelse continue; @@ -199,7 +199,7 @@ test "Mini maps every braille dot and partial line group" { for (0..2) |col| source[row * 3 + col] = if (mask & (@as(usize, 1) << bits[row][col]) != 0) 'x' else ' '; source[row * 3 + 2] = '\n'; } - const result = try generate(gpa, &source, ""); + const result = try generate(config.tab_width, gpa, &source, ""); defer result.deinit(gpa); var expected: [4]u8 = undefined; const len: usize = if (mask == 0) 0 else try std.unicode.utf8Encode(@as(u21, 0x2800) + @as(u21, @intCast(mask)), &expected); @@ -216,7 +216,7 @@ test "Mini maps every braille dot and partial line group" { .{ .source = "\n\n\n\nx", .expected = "\n⠁\n" }, .{ .source = "x\r\nx\r\n", .expected = "⠃\n" }, }) |case| { - const result = try generate(gpa, case.source, ""); + const result = try generate(config.tab_width, gpa, case.source, ""); defer result.deinit(gpa); try std.testing.expectEqualStrings(case.expected, result.content); } @@ -229,15 +229,15 @@ test "Mini uses display cells for tabs combining text and wide characters" { .{ .source = " x\n", .expected = " ⠁\n" }, .{ .source = "\u{a0}x\n", .expected = "⠈\n" }, }) |case| { - const result = try generate(gpa, case.source, ""); + const result = try generate(config.tab_width, gpa, case.source, ""); defer result.deinit(gpa); try std.testing.expectEqualStrings(case.expected, result.content); } - const tabs = try generate(gpa, "\tx\n", ""); + const tabs = try generate(config.tab_width, gpa, "\tx\n", ""); defer tabs.deinit(gpa); - const spaces = config.tab_now / 2; + const spaces = config.tab_width / 2; for (tabs.content[0..spaces]) |byte| try std.testing.expectEqual(@as(u8, ' '), byte); - try std.testing.expectEqualStrings(if (config.tab_now % 2 == 0) "⠁\n" else "⠈\n", tabs.content[spaces..]); + try std.testing.expectEqualStrings(if (config.tab_width % 2 == 0) "⠁\n" else "⠈\n", tabs.content[spaces..]); } test "Mini chooses highlighted dots over plain ink with stable color ties" { @@ -245,17 +245,17 @@ test "Mini chooses highlighted dots over plain ink with stable color ties" { const source = "xx\nxx\nxx\nxx\n"; var styles: [source.len]u8 = @splat(0); styles[0] = @backingInt(syntax.Syn.keyword); - const rare = try generate(gpa, source, &styles); + const rare = try generate(config.tab_width, gpa, source, &styles); defer rare.deinit(gpa); try std.testing.expectEqualStrings("⣿\n", rare.content); try std.testing.expectEqualSlices(u8, &.{ 1, 1, 1, 0 }, rare.colors); styles[0] = @backingInt(syntax.Syn.string); styles[1] = @backingInt(syntax.Syn.number); - const tied = try generate(gpa, source, &styles); + const tied = try generate(config.tab_width, gpa, source, &styles); defer tied.deinit(gpa); try std.testing.expectEqualSlices(u8, &.{ 2, 2, 2, 0 }, tied.colors); styles[3] = @backingInt(syntax.Syn.number); - const majority = try generate(gpa, source, &styles); + const majority = try generate(config.tab_width, gpa, source, &styles); defer majority.deinit(gpa); try std.testing.expectEqualSlices(u8, &.{ 3, 3, 3, 0 }, majority.colors); } @@ -263,19 +263,19 @@ test "Mini chooses highlighted dots over plain ink with stable color ties" { test "Mini generation bounds and allocation failures leave no partial result" { const Case = struct { fn run(gpa: std.mem.Allocator) !void { - const result = try generate(gpa, "alpha\nbeta\ngamma\ndelta\nepsilon\n", ""); + const result = try generate(config.tab_width, gpa, "alpha\nbeta\ngamma\ndelta\nepsilon\n", ""); defer result.deinit(gpa); } }; try std.testing.checkAllAllocationFailures(std.testing.allocator, Case.run, .{}); - try std.testing.expectError(error.InvalidMiniColors, generate(std.testing.allocator, "x", &.{5})); - try std.testing.expectError(error.InvalidMiniColors, generate(std.testing.allocator, "xx", &.{0})); + try std.testing.expectError(error.InvalidMiniColors, generate(config.tab_width, std.testing.allocator, "x", &.{5})); + try std.testing.expectError(error.InvalidMiniColors, generate(config.tab_width, std.testing.allocator, "xx", &.{0})); var allocator = std.testing.FailingAllocator.init(std.testing.allocator, .{ .fail_index = 0 }); const source = try std.testing.allocator.alloc(u8, max_input_bytes + 1); defer std.testing.allocator.free(source); - try std.testing.expectError(error.MiniTooLarge, generate(allocator.allocator(), source, "")); + try std.testing.expectError(error.MiniTooLarge, generate(config.tab_width, allocator.allocator(), source, "")); for (source[0..max_input_bytes], 0..) |*byte, i| byte.* = if (i % 2 == 0) 'x' else ' '; - try std.testing.expectError(error.MiniTooLarge, generate(allocator.allocator(), source[0..max_input_bytes], "")); + try std.testing.expectError(error.MiniTooLarge, generate(config.tab_width, allocator.allocator(), source[0..max_input_bytes], "")); try std.testing.expect(!allocator.has_induced_failure); } @@ -327,5 +327,5 @@ test "Mini publishes only complete snapshots and content replacement drops metad } test "Mini refuses a file that is no UTF-8, before its decoding could panic" { - try std.testing.expectError(error.InvalidUtf8, generate(std.testing.allocator, "ok \xff\xfe bad\n\xc3", "")); + try std.testing.expectError(error.InvalidUtf8, generate(config.tab_width, std.testing.allocator, "ok \xff\xfe bad\n\xc3", "")); } diff --git a/core/mouse.zig b/core/mouse.zig index 073f09c3..8e761453 100644 --- a/core/mouse.zig +++ b/core/mouse.zig @@ -375,7 +375,7 @@ fn headerPoint(p: *Pardes, column: ?usize, mcol: u16, mrow: u16, clamp: bool) ?s const bar = modal.lineSlice(text, line); const scroll = if (focused) v.header_scroll else 0; const kind: Layer.Kind = if (column != null) .column else .workspace; - const at = @min(bar.len, panes.File.rawAtDisplay(bar, (Layer.columnAt(p, kind, column orelse 0, v.pointer_tag_hit, clamp, row) orelse (mcol -| x)) + scroll)); + const at = @min(bar.len, panes.File.rawAtDisplay(p.settings.tab, bar, (Layer.columnAt(p, kind, column orelse 0, v.pointer_tag_hit, clamp, row) orelse (mcol -| x)) + scroll)); return .{ .t = t, .text = text, .line = line, .at = modal.lineStartOffset(text, line) + at }; } @@ -451,8 +451,8 @@ fn chordCutPaste(p: *Pardes, cut: bool) edit.Error!void { const pfx: i32 = if (pane.file != null) panes.File.gutterWidth(pane) else 0; // both ends of the sweep through the same last-frame map, so a // chord over wrapped rows cuts the text that was under it - const w0 = pane.wrapAt(@max(0, sl.r0 - @as(i32, pane.tag_rows))); - const w1 = pane.wrapAt(@max(0, sl.r1 - @as(i32, pane.tag_rows))); + const w0 = pane.wrapAt(p.settings.tab, @max(0, sl.r0 - @as(i32, pane.tag_rows))); + const w1 = pane.wrapAt(p.settings.tab, @max(0, sl.r1 - @as(i32, pane.tag_rows))); const row0 = w0.line; const row1 = w1.line; const col0 = edit.paneByteAtDisplay(p.editor(), &pane.body, w0.line, w0.at, sl.c0 - pfx - w0.pad); @@ -490,7 +490,7 @@ fn chordCutPaste(p: *Pardes, cut: bool) edit.Error!void { } pane.body.cur_pinned = true; pane.body.sticky_col = -1; - pane.ensureCursorVisible(); + pane.ensureCursorVisible(p.settings.tab); } else try edit.pasteText(p.editor(), &pane.body, p.registers.text(p.gpa, pardes.Registers.default) orelse return, true, 1); } @@ -711,12 +711,12 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { } else if (pane.file != null and !p.settings.wrap) { // wrapped there is nothing off to the right to reach const line = panes.File.sourceLine(pane, pane.body.cur_row); - const visual = panes.File.rawDisplayCol(line, @intCast(@max(0, pane.hscroll))); + const visual = panes.File.rawDisplayCol(p.settings.tab, line, @intCast(@max(0, pane.hscroll))); const next: usize = if (m.button == .wheel_right) visual +| @as(usize, @intCast(config.wheel_cols)) else visual -| @as(usize, @intCast(config.wheel_cols)); - pane.hscroll = @intCast(panes.File.rawAtDisplay(line, next)); + pane.hscroll = @intCast(panes.File.rawAtDisplay(p.settings.tab, line, next)); } }, config.select_button => switch (m.kind) { @@ -773,7 +773,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { const rail_h = r.h -| pane.tag_rows; if (mrow >= body_y and mrow < body_y + rail_h) if (pane.places.tickHit(p, pane, mrow - body_y, rail_h)) |i| { pane.focus = .body; - return pane.places.goTo(pane, i, false); + return pane.places.goTo(p.settings.tab, pane, i, false); }; // gutter scrollbar: a left click scrolls UP to that row pane.scrollBy(-(@as(i32, mrow) - @as(i32, body_y))); @@ -905,7 +905,7 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo const r = v.rects[s.id]; const b = @backingInt(s.button); const tag_rows: i32 = pane.tag_rows; - panes.File.geometry(pane); + panes.File.geometry(p.settings.tab, pane); if (pane.body_rows > 0 and pane.sel[b].r0 >= tag_rows) if (body_hit) |supplied| { if (supplied.serial == pane.serial) s.body = supplied.place; const mapped_hit = bodyHitForPane(p, s.id, supplied, true) orelse return; @@ -1015,7 +1015,7 @@ fn gestureRange(p: *Pardes, id: usize, text: []const u8, on_tag: bool, operand: const lead = if (sel.r0 < sel.r1 or (sel.r0 == sel.r1 and sel.c0 <= sel.c1)) sel else Pane.Sel{ .r0 = sel.r1, .c0 = sel.c1 }; const row: usize = @as(usize, @intCast(@max(0, lead.r0))) + pane.tag_top; const start = modal.lineStartOffset(shown.text, row); - const at = shown.toReal(start + panes.File.rawAtDisplay(modal.lineSlice(shown.text, row), @intCast(@max(0, lead.c0)))); + const at = shown.toReal(start + panes.File.rawAtDisplay(p.settings.tab, modal.lineSlice(shown.text, row), @intCast(@max(0, lead.c0)))); const q0: u32 = @intCast(@min(at, tag.len)); return .{ .q0 = q0, .q1 = @intCast(@min(q0 + text.len, tag.len)) }; } @@ -1041,7 +1041,7 @@ fn gestureRange(p: *Pardes, id: usize, text: []const u8, on_tag: bool, operand: const lead = edit.sweepEnds(sel)[0]; const top = lead[0] - @as(i32, pane.tag_rows); if (top < 0) break :lead null; - const w = pane.wrapAt(top); + const w = pane.wrapAt(p.settings.tab, top); const col = edit.paneByteAtDisplay(p.editor(), &pane.body, w.line, w.at, lead[1] - panes.File.gutterWidth(pane) - w.pad); break :lead .{ .row = @intCast(@max(0, w.line)), @@ -1089,7 +1089,7 @@ fn mirrorTtySelection(p: *Pardes, pane: *Pane) void { if (rows.len == 0) return; const forward = gesture.r1 > gesture.r0 or (gesture.r1 == gesture.r0 and gesture.c1 >= gesture.c0); const endpoint = rows[if (forward) rows.len - 1 else 0]; - const body = body_layer.bodyText(p.scratch.allocator(), pane) catch |err| return p.reportError(p.view().active, "select", err); + const body = body_layer.bodyText(p.settings.tab, p.scratch.allocator(), pane) catch |err| return p.reportError(p.view().active, "select", err); const line = modal.lineSlice(body, @intCast(@max(0, endpoint.row - @as(i32, @intCast(panes.Term.grid(pane.terminal).offset))))); const byte = if (forward) modal.prevGrapheme(line, @min(endpoint.hi, line.len)) else endpoint.lo; pane.body.cur_row = pane.surfRow(endpoint.row); @@ -1158,7 +1158,7 @@ pub fn edgeScroll(p: *Pardes) void { fn sweepPoint(p: *Pardes, pane: *panes.Pane, r: i32, c: i32) ?modal.Cursor { const visible = r - @as(i32, pane.tag_rows); if (visible < 0) return null; - const w = pane.wrapAt(visible); + const w = pane.wrapAt(p.settings.tab, visible); if (w.line < 0) return null; const col = edit.paneByteAtDisplay(p.editor(), &pane.body, w.line, w.at, c - w.pad - (if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) else 0)); return .{ .row = @intCast(w.line), .col = @intCast(@max(0, col)) }; @@ -1204,7 +1204,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { // click on the path, if it can be renamed, drafts a name. const row: usize = @intCast(@max(0, sl.r1)); const col: usize = @intCast(@max(0, sl.c1)); - if (!dragged and tagline.onName(pane, row, col)) { + if (!dragged and tagline.onName(p.settings.tab, pane, row, col)) { tagline.draftName(p, pane, col); } else if (tagline.tagOffsetAt(p, pane, row, col)) |cursor| { pane.tag.cur_row = @intCast(cursor.row); @@ -1217,7 +1217,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { if (dragged and pane.body.mode == .tty) mirrorTtySelection(p, pane); const body_vis = sl.r1 - @as(i32, pane.tag_rows); if (body_vis >= 0 and pane.body.mode != .tty) { - const w = pane.wrapAt(body_vis); + const w = pane.wrapAt(p.settings.tab, body_vis); pane.body.cur_row = w.line; pane.body.cur_col = edit.paneByteAtDisplay( p.editor(), @@ -1227,7 +1227,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { sl.c1 - w.pad - (if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) else 0), ); pane.body.cur_pinned = true; - if (edit.clampFileCursor(&pane.body)) pane.ensureCursorVisible(); + if (edit.clampFileCursor(&pane.body)) pane.ensureCursorVisible(p.settings.tab); pane.body.normal.clear(); pane.body.vsel.active = false; pane.body.nsel = 0; // a click says WHERE the one cursor is @@ -1253,7 +1253,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { if (s.button == config.look_button and clk.r0 >= pane.tag_rows and clk.r0 == clk.r1 and clk.c0 == clk.c1 and clk.c0 >= 0 and pane.body.mode != .tty) if (pane.file) |f| if (f.output == null and clk.c0 < panes.File.gutterWidth(pane)) { - const line = pane.wrapAt(clk.r0 - pane.tag_rows).line; + const line = pane.wrapAt(p.settings.tab, clk.r0 - pane.tag_rows).line; if (line >= 0) { pane.sel[b].state = .none; var buf: [48]u8 = undefined; @@ -1276,18 +1276,18 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { pane.body.select = false; pane.body.cur_row = operand.row; pane.body.cur_col = operand.col; - if (edit.clampFileCursor(&pane.body)) pane.ensureCursorVisible(); + if (edit.clampFileCursor(&pane.body)) pane.ensureCursorVisible(p.settings.tab); } const txt = operand.text; const cmd = if (s.button == config.look_button) config.look_cmd else config.exec_cmd; if (clk.r0 == 0 and s.button == config.exec_button and pane.prompt == .name) { - const prefix_width = panes.File.displayWidth(tagline.tagPrefix(p, pane) catch return); + const prefix_width = panes.File.displayWidth(p.settings.tab, tagline.tagPrefix(p, pane) catch return); const on_name = @as(usize, @intCast(@max(0, clk.c0))) < prefix_width; if (!tagline.commitTagName(p, pane)) return; // Executing a staged filename commits it; executing its // command tail uses the new identity (especially Save). if (on_name) return; - const new_width = panes.File.displayWidth(tagline.tagPrefix(p, pane) catch return); + const new_width = panes.File.displayWidth(p.settings.tab, tagline.tagPrefix(p, pane) catch return); const shift = @as(i32, @intCast(new_width)) - @as(i32, @intCast(prefix_width)); if (operand.expanded) |*sel| { sel.c0 += shift; @@ -1479,7 +1479,7 @@ test "mouse thumb buttons navigate once and clear selection gestures" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 }); defer p.deinit(); const pane = try p.setTestFile("alpha beta\ngamma delta\nepsilon zeta\n"); - pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true); + pane.body.setRange(config.tab_width, pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true); p.view().jumps.n = 3; p.view().jumps.cur = 2; for (0..3) |i| p.view().jumps.list[i] = .{ .pane = 0, .serial = pane.serial, .line = @intCast(i + 1), .col = 1 }; @@ -1504,7 +1504,7 @@ test "a chorded exec an event reader holds is told with its argument, and writte const event = ctlfs.Node.of(serial, .event); const h = th.call(p, .{ .tag = 1, .op = .open, .node = event, .omode = 2 }).reply.handle; // The argument: a selection held in the pane (its second line). - ctlfs.pane.setDot(p.panes[0].?, .{ .q0 = 9, .q1 = 17 }); + ctlfs.pane.setDot(p.settings.tab, p.panes[0].?, .{ .q0 = 9, .q1 = 17 }); p.view().chord_arg = try p.gpa.dupe(u8, "arg-text"); dispatchPointerBuiltin(p, 0, config.exec_cmd, "Msg", .{ .on_tag = false, .operand = .{ .row = 0, .col = 1, .text = "Msg" } }); var records: [3][]const u8 = undefined; diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig index 0077f095..2f008927 100644 --- a/core/ninep/ctl.zig +++ b/core/ninep/ctl.zig @@ -439,7 +439,7 @@ pub fn paneText(p: *Pardes, pane: *Pane, buf: *[pane_text_cap]u8) []const u8 { const f = pane_files.fileOf(pane); const undo = if (f) |file| file.history.journal.done > 0 else false; const redo = if (f) |file| file.history.journal.done < file.history.journal.steps.items.len else false; - w.print(" {d:>11} {d:>11} {d:>11} {s} ", .{ config.tab_now, @intFromBool(undo), @intFromBool(redo), if (current) "current" else "notcurrent" }) catch break :fill; + w.print(" {d:>11} {d:>11} {d:>11} {s} ", .{ p.settings.tab, @intFromBool(undo), @intFromBool(redo), if (current) "current" else "notcurrent" }) catch break :fill; // A terminal bound as a REPL ends with its id, `python-a`. var idbuf: [48]u8 = undefined; const id = exec_line.replId(&idbuf, pane); @@ -1202,10 +1202,10 @@ fn acmeCtl(p: *Pardes, req: Req, serial: u32, line: []const u8, apply: bool) Acm .delete => return .{ .builtin = "Delete" }, .@"dot=addr", .@"addr=dot", .@"limit=addr", .show, .cleartag => { if (apply) switch (w) { - .@"dot=addr" => pane_files.setDot(pane, pf.addr), + .@"dot=addr" => pane_files.setDot(p.settings.tab, pane, pf.addr), .@"addr=dot" => pf.addr = pane_files.dotOf(pane), .@"limit=addr" => pf.limit = pf.addr, - .show => pane_files.showOffset(pane, pane_files.dotOf(pane).q0), + .show => pane_files.showOffset(p.settings.tab, pane, pane_files.dotOf(pane).q0), else => _ = pane_files.truncate(p, pane, .tag), }; return .done; @@ -1344,7 +1344,7 @@ test "pane ctl read is acme's fields -- index's five, width in cells, font, tab var want: std.ArrayList(u8) = .empty; defer want.deinit(gpa); try want.print(gpa, "{d:>11} {d:>11} {d:>11} {d:>11} {d:>11} {d:>11} {s} {d:>11} {d:>11} {d:>11} current mode:normal ", .{ - pane.serial, (try pane_files.tagOf(p, pane)).len, @as(usize, 2), 0, 0, pane.cols, "default", config.tab_now, 0, 0, + pane.serial, (try pane_files.tagOf(p, pane)).len, @as(usize, 2), 0, 0, pane.cols, "default", p.settings.tab, 0, 0, }); try testing.expectEqualStrings(want.items, a.bytes); try testing.expectEqual(@as(u64, a.bytes.len), call(p, .{ .tag = 1, .op = .getattr, .node = Node.of(pane.serial, .ctl) }).reply.attr.size); diff --git a/core/ninep/events.zig b/core/ninep/events.zig index 276261c8..6946401b 100644 --- a/core/ninep/events.zig +++ b/core/ninep/events.zig @@ -1341,7 +1341,7 @@ test "an empty range written back is expanded as a click at that point would be" const pane = p.panes[p.paneBySerial(serial).?].?; const event = Node.of(serial, .event); // A look at 1 is a look at `abc`: from dot, past the first, the next. - pane_files.setDot(pane, .{ .q0 = 4, .q1 = 4 }); + pane_files.setDot(p.settings.tab, pane, .{ .q0 = 4, .q1 = 4 }); try testing.expectEqual(Status.ok, wr(p, event, "ML1 1\n").reply.status); try testing.expectEqual(pane_files.State.Range{ .q0 = 8, .q1 = 11 }, pane_files.dotOf(pane)); // An exec at 15 runs the word there, `Newcol`. @@ -1386,7 +1386,7 @@ test "a click in the body reports the offsets of the word it takes, so the recor const rect = p.view().rects[id]; const x0 = rect.x + config.GUTTER + config.PREFIX_W; const y0 = rect.y + p.panes[id].?.tag_rows; - const tab: u16 = config.tab_now; + const tab: u16 = p.settings.tab; const Click = struct { x: u16, y: u16, look: []const u8, exec: []const u8, scroll: i32 = 0 }; // Where the wrapped line's `qty` landed, as drawn. const surface = try p.render(frame.allocator()); diff --git a/core/ninep/pane.zig b/core/ninep/pane.zig index 11f0558e..e9e43095 100644 --- a/core/ninep/pane.zig +++ b/core/ninep/pane.zig @@ -228,7 +228,7 @@ pub fn dotOf(pane: *Pane) State.Range { return .{ .q0 = clip(@min(head, anchor)), .q1 = clip(hi) }; } -pub fn setDot(pane: *Pane, r: State.Range) void { +pub fn setDot(tab: u16, pane: *Pane, r: State.Range) void { const text = bodyOf(pane); const q0 = @min(@as(usize, r.q0), text.len); const q1 = @max(q0, @min(@as(usize, r.q1), text.len)); @@ -239,13 +239,13 @@ pub fn setDot(pane: *Pane, r: State.Range) void { pane.body.cur_col = @intCast(h.col); pane.body.cur_pinned = true; pane.body.sticky_col = -1; - pane.ensureCursorVisible(); + pane.ensureCursorVisible(tab); } /// Scrolls `off` into view and nothing else: the cursor is dot's head, and /// a write shown is not a write that moves dot (acme's textinsert leaves /// dot where its rule puts it; only the view follows the text). -pub fn showOffset(pane: *Pane, off: usize) void { +pub fn showOffset(tab: u16, pane: *Pane, off: usize) void { const text = bodyOf(pane); const c = positionAt(pane, text, @min(off, text.len)); // Where dot is now, kept: pinned, so the view moving under it does not @@ -255,7 +255,7 @@ pub fn showOffset(pane: *Pane, off: usize) void { const col = pane.body.cur_col; pane.body.cur_row = @intCast(c.row); pane.body.cur_col = @intCast(c.col); - pane.ensureCursorVisible(); + pane.ensureCursorVisible(tab); pane.body.cur_row = row; pane.body.cur_col = col; } @@ -497,7 +497,7 @@ pub fn write(p: *Pardes, req: Req, id: usize, pane: *Pane, file: PaneFile) Reply .body => writeBody(p, req, id, pane), .tag => writeTag(p, req, pane), .ctl => ctl.writePane(p, req, pane), - .addr, .dot, .limit => writeRange(req, pane, file), + .addr, .dot, .limit => writeRange(p.settings.tab, req, pane, file), .data, .xdata => writeData(p, req, pane), .sel => writeSel(p, req, pane), .dirty, .mark, .scroll => writeFlag(p, req, pane, file), @@ -583,11 +583,11 @@ pub fn flushBatch(p: *Pardes) void { if (fileOf(pane) == null) return; const before = dotOf(pane); const take = spliceJoined(p, pane, b.at, b.at, b.bytes.items, b.handle) orelse return; - setDot(pane, .{ + setDot(p.settings.tab, pane, .{ .q0 = shiftOne(before.q0, clip(b.at), 0, clip(take)), .q1 = shiftOne(before.q1, clip(b.at), 0, clip(take)), }); - if (!pane.fs.noscroll) showOffset(pane, b.at + take); + if (!pane.fs.noscroll) showOffset(p.settings.tab, pane, b.at + take); } /// How many bytes this open's write holds back (`fs.batch`) for its pane. @@ -627,7 +627,7 @@ fn writeBody(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply { if (holdWrite(p, req, pane, at) catch return Reply.fail(req.tag, E.NOMEM)) |take| return .{ .tag = req.tag, .written = @intCast(take) }; const take = spliceJoined(p, pane, at, at, req.data, req.handle) orelse return Reply.fail(req.tag, E.NOMEM); - if (!pane.fs.noscroll) showOffset(pane, at + take); + if (!pane.fs.noscroll) showOffset(p.settings.tab, pane, at + take); return .{ .tag = req.tag, .written = @intCast(take) }; } @@ -728,12 +728,12 @@ fn writeData(p: *Pardes, req: Req, pane: *Pane) Reply { const before = dotOf(pane); const take = spliceJoined(p, pane, q0, q1, req.data, req.handle) orelse return Reply.fail(req.tag, E.NOMEM); - setDot(pane, .{ + setDot(p.settings.tab, pane, .{ .q0 = shiftOne(before.q0, clip(q0), clip(q1 - q0), clip(take)), .q1 = shiftOne(before.q1, clip(q0), clip(q1 - q0), clip(take)), }); pf.addr = .{ .q0 = clip(q0 + take), .q1 = clip(q0 + take) }; - if (!pf.noscroll) showOffset(pane, q0 + take); + if (!pf.noscroll) showOffset(p.settings.tab, pane, q0 + take); return .{ .tag = req.tag, .written = @intCast(take) }; } @@ -752,7 +752,7 @@ fn writeSel(p: *Pardes, req: Req, pane: *Pane) Reply { const start = if (going_on) pf.wrsel.q0 else clip(q0); pf.wrsel = .{ .q0 = start, .q1 = clip(q0 + take) }; pf.wrsel_by = req.handle; - setDot(pane, pf.wrsel); + setDot(p.settings.tab, pane, pf.wrsel); return .{ .tag = req.tag, .written = @intCast(take) }; } @@ -774,7 +774,7 @@ pub const e_addr_failed = "no address: the last one written to addr failed"; /// that does not evaluate says why: `bad address syntax`, `no match for /// regexp`, `address out of range`, `bad regular expression`, `addresses /// out of order`. -fn writeRange(req: Req, pane: *Pane, file: PaneFile) Reply { +fn writeRange(tab: u16, req: Req, pane: *Pane, file: PaneFile) Reply { // A terminal, an image or a PDF has no text an address names: refused // alike for addr, dot and limit, before the expression is read. if (fileOf(pane) == null) return tree.failText(req.tag, E.INVAL, e_no_text_address); @@ -820,7 +820,7 @@ fn writeRange(req: Req, pane: *Pane, file: PaneFile) Reply { }, .limit => pf.limit = range, // Setting dot scrolls to it, which is the whole of acme's `show`. - .dot => setDot(pane, range), + .dot => setDot(tab, pane, range), else => unreachable, } return .{ .tag = req.tag, .written = @intCast(req.data.len) }; @@ -993,7 +993,7 @@ pub fn truncate(p: *Pardes, pane: *Pane, file: PaneFile) tree.Status { pf.joined = if (fileOf(pane).?.revision != was) fileOf(pane).?.revision else null; pf.joined_by = 0; pf.addr = .{}; - setDot(pane, .{}); + setDot(p.settings.tab, pane, .{}); }, .data, .xdata => if (fileOf(pane) != null) { clampAddr(pf, bodyOf(pane).len); @@ -1005,7 +1005,7 @@ pub fn truncate(p: *Pardes, pane: *Pane, file: PaneFile) tree.Status { _ = spliceBody(p, pane, q0, q1, "") orelse return .err; pf.joined = if (fileOf(pane).?.revision != was) fileOf(pane).?.revision else null; pf.joined_by = 0; - setDot(pane, .{ .q0 = shiftOne(before.q0, q0, q1 - q0, 0), .q1 = shiftOne(before.q1, q0, q1 - q0, 0) }); + setDot(p.settings.tab, pane, .{ .q0 = shiftOne(before.q0, q0, q1 - q0, 0), .q1 = shiftOne(before.q1, q0, q1 - q0, 0) }); pf.addr = .{ .q0 = q0, .q1 = q0 }; }, // Done with the write after it, which may yet be refused. diff --git a/core/ninep/tree.zig b/core/ninep/tree.zig index d13a1b19..d95efb8c 100644 --- a/core/ninep/tree.zig +++ b/core/ninep/tree.zig @@ -1019,7 +1019,7 @@ fn releaseHandle(p: *Pardes, req: Req) void { .limit => pn.fs.limit_truncated = null, // `: > dot` empties it once its open goes, no write having set it. .dot => { - if (pn.fs.dot_truncated) pane.setDot(pn, .{}); + if (pn.fs.dot_truncated) pane.setDot(p.settings.tab, pn, .{}); pn.fs.dot_truncated = false; }, else => {}, diff --git a/core/normal.zig b/core/normal.zig index 869394fc..fb392647 100644 --- a/core/normal.zig +++ b/core/normal.zig @@ -116,9 +116,9 @@ pub fn selectByRegex(e: Editor, t: *Text, snap: []modal.Selection, pri: usize, e r.anchor = @min(r.anchor, text.len); r.head = @min(r.head, text.len); } - return t.setRanges(text, snap, &.{}, pri, expl); + return t.setRanges(e.tab, text, snap, &.{}, pri, expl); } - t.setRanges(text, out[0..m], &.{}, 0, true); // helix keeps primary 0 (its own TODO) + t.setRanges(e.tab, text, out[0..m], &.{}, 0, true); // helix keeps primary 0 (its own TODO) } fn lastMatch(re: *SearchRegex, hay: []const u8, from: usize, to: usize) ?regexp.Regex.Match { @@ -251,10 +251,10 @@ fn objectJump(e: Editor, t: *Text, text: []const u8, range: modal.Selection, obj if (std.meta.eql(last, range)) return; if (t.select) { const head = if (last.head < range.anchor) last.anchor else last.head; - return t.setRange(text, 0, .{ .anchor = range.anchor, .head = head }, false); + return t.setRange(e.tab, text, 0, .{ .anchor = range.anchor, .head = head }, false); } const out: modal.Selection = if (forward) last else .{ .anchor = last.head, .head = last.anchor }; - t.setRange(text, 0, out, false); + t.setRange(e.tab, text, 0, out, false); } /// helix's tree-sitter selection keys: every range walks the text's parse @@ -279,7 +279,7 @@ pub fn nodeSelect(e: Editor, t: *Text, text: []const u8, walk: modal.Normal.Node } else false) continue; break false; } else true; - if (holds) return t.setRanges(text, prev.ranges, &.{}, prev.primary, expl); + if (holds) return t.setRanges(e.tab, text, prev.ranges, &.{}, prev.primary, expl); for (tree.history.items) |step| tree.gpa.free(step.ranges); tree.history.clearRetainingCapacity(); }; @@ -322,7 +322,7 @@ pub fn nodeSelect(e: Editor, t: *Text, text: []const u8, walk: modal.Normal.Node const ranges = tree.gpa.dupe(modal.Selection, rs[0..got.n]) catch break :remember; tree.history.append(tree.gpa, .{ .ranges = ranges, .primary = got.pri }) catch tree.gpa.free(ranges); } - t.setRanges(text, out[0..m], &.{}, @min(got.pri, m - 1), expl); + t.setRanges(e.tab, text, out[0..m], &.{}, @min(got.pri, m - 1), expl); } /// `gw` (helix goto_word): label the words in view, nearest the cursor first, @@ -356,11 +356,11 @@ pub fn jumpKey(p: *Pardes, pane: *Pane, t: *Text, key: Key) void { if (chosen >= pane.jump.items.len) return; const r = pane.jump.items[chosen]; const text = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(p.view().active, "edit", err); - if (!t.select) return t.setRange(text, 0, .{ .anchor = @min(r.anchor, r.head), .head = @max(r.anchor, r.head) }, true); + if (!t.select) return t.setRange(p.settings.tab, text, 0, .{ .anchor = @min(r.anchor, r.head), .head = @max(r.anchor, r.head) }, true); // select mode stretches the primary to the word (helix Movement::Extend) const pr = t.primaryRange(text, 0); const anchor = if (r.anchor < r.head) @min(r.anchor, @min(pr.anchor, pr.head)) else @max(r.anchor, @max(pr.anchor, pr.head)); - t.setRange(text, 0, .{ .anchor = anchor, .head = r.head }, true); + t.setRange(p.settings.tab, text, 0, .{ .anchor = anchor, .head = r.head }, true); } const KeyState = struct { @@ -509,9 +509,9 @@ pub fn replaySels(e: Editor, t: *Text, what: Replay) void { rs[k] = Text.cellOffRange(text, text.len - @min(r.anc, text.len), text.len - @min(r.cur, text.len)); st[k] = r.sticky; } - t.setRanges(text, rs[0..n], st[0..n], pri, after_expl); + t.setRanges(e.tab, text, rs[0..n], st[0..n], pri, after_expl); after.into(t); - t.show(); // the view follows the PRIMARY, not the last pass + t.show(e.tab); // the view follows the PRIMARY, not the last pass } fn normalInput(key: Key) modal.Normal.Input { @@ -630,14 +630,14 @@ fn searchStep(e: Editor, t: *Text, text: []const u8, forward: bool, count: u32) .{ .anchor = found.start, .head = found.end }; if (t.select and got.n < ranges.len) { ranges[got.n] = next; - t.setRanges(text, ranges[0 .. got.n + 1], &.{}, got.n, true); + t.setRanges(e.tab, text, ranges[0 .. got.n + 1], &.{}, got.n, true); } else { ranges[got.pri] = next; - t.setRanges(text, ranges[0..got.n], &.{}, got.pri, true); + t.setRanges(e.tab, text, ranges[0..got.n], &.{}, got.pri, true); } if (wrapped) e.p.setMessage(v.active, "wrapped around document"); } - t.show(); + t.show(e.tab); } pub fn searchSelection(e: Editor, t: *Text, text: []const u8, boundary: bool) edit.Error!void { @@ -658,7 +658,7 @@ pub fn searchSelection(e: Editor, t: *Text, text: []const u8, boundary: bool) ed e.registers.last_search = name; } -fn multiSelAction(t: *Text, text: []const u8, role: modal.Normal.Role, cnt: usize) void { +fn multiSelAction(tab: u16, t: *Text, text: []const u8, role: modal.Normal.Role, cnt: usize) void { var rs: [Text.max_selections]modal.Selection = undefined; const got = t.ranges(text, 0, &rs); const n = got.n; @@ -674,12 +674,12 @@ fn multiSelAction(t: *Text, text: []const u8, role: modal.Normal.Role, cnt: usiz } // helix Selection::remove: the NEXT range takes over, or the // previous one when the primary was last - return t.setRanges(text, out[0..m], &.{}, @min(got.pri, m - 1), expl); + return t.setRanges(tab, text, out[0..m], &.{}, @min(got.pri, m - 1), expl); } if (role == .rotate_sel_fwd or role == .rotate_sel_back) { const turn = cnt % n; const pri = if (role == .rotate_sel_fwd) (got.pri + turn) % n else (got.pri + (n - turn)) % n; - return t.setRanges(text, rs[0..n], &.{}, pri, expl); + return t.setRanges(tab, text, rs[0..n], &.{}, pri, expl); } if (role == .merge_sels) { // helix merge_selections: first.merge(last) — the ranges are @@ -688,7 +688,7 @@ fn multiSelAction(t: *Text, text: []const u8, role: modal.Normal.Role, cnt: usiz const hi = @max(rs[n - 1].anchor, rs[n - 1].head); const rev = rs[0].anchor > rs[0].head and rs[n - 1].anchor > rs[n - 1].head; const one: modal.Selection = if (rev) .{ .anchor = hi, .head = lo } else .{ .anchor = lo, .head = hi }; - return t.setRanges(text, &.{one}, &.{}, 0, expl); + return t.setRanges(tab, text, &.{one}, &.{}, 0, expl); } if (role == .merge_consecutive_sels) { var out: [Text.max_selections]modal.Selection = undefined; @@ -706,7 +706,7 @@ fn multiSelAction(t: *Text, text: []const u8, role: modal.Normal.Role, cnt: usiz out[m] = r; m += 1; } - return t.setRanges(text, out[0..m], &.{}, pri, expl); + return t.setRanges(tab, text, out[0..m], &.{}, pri, expl); } if (role == .ensure_forward) { // helix ensure_selections_forward: every range points forward @@ -715,7 +715,7 @@ fn multiSelAction(t: *Text, text: []const u8, role: modal.Normal.Role, cnt: usiz r.head = @max(r.anchor, r.head); r.anchor = from; } - return t.setRanges(text, rs[0..n], &.{}, got.pri, expl); + return t.setRanges(tab, text, rs[0..n], &.{}, got.pri, expl); } if (role == .split_sel_newline) { // helix selection::split_on_newline — one range per line the @@ -746,7 +746,7 @@ fn multiSelAction(t: *Text, text: []const u8, role: modal.Normal.Role, cnt: usiz } } if (m == 0) return; - return t.setRanges(text, out[0..m], &.{}, 0, true); // helix keeps primary 0 + return t.setRanges(tab, text, out[0..m], &.{}, 0, true); // helix keeps primary 0 } if (role == .trim_sels) { // helix trim_selections: whitespace off both ends; ranges that are @@ -764,7 +764,7 @@ fn multiSelAction(t: *Text, text: []const u8, role: modal.Normal.Role, cnt: usiz } if (m == 0) { // helix: collapse_selection + keep_primary_selection const c = modal.selectionCursor(text, rs[got.pri]); - return t.setRange(text, 0, .{ .anchor = c, .head = c }, false); + return t.setRange(tab, text, 0, .{ .anchor = c, .head = c }, false); } // helix: the first survivor that OVERLAPS the old primary, else the last const pf = @min(rs[got.pri].anchor, rs[got.pri].head); @@ -778,7 +778,7 @@ fn multiSelAction(t: *Text, text: []const u8, role: modal.Normal.Role, cnt: usiz break; } } - return t.setRanges(text, out[0..m], &.{}, pri, expl); + return t.setRanges(tab, text, out[0..m], &.{}, pri, expl); } const below = role == .copy_sel_below; var out: [Text.max_selections]modal.Selection = undefined; @@ -814,7 +814,7 @@ fn multiSelAction(t: *Text, text: []const u8, role: modal.Normal.Role, cnt: usiz if (arow == 0 and hrow == 0) break; } } - t.setRanges(text, out[0..m], &.{}, pri, expl); + t.setRanges(tab, text, out[0..m], &.{}, pri, expl); } fn maxLine(text: []const u8) usize { @@ -823,26 +823,26 @@ fn maxLine(text: []const u8) usize { } /// point-target motion: collapse there (extend in select mode) -fn pointMove(t: *Text, text: []const u8, range: modal.Selection, target: usize) void { - t.setRange(text, 0, modal.moveSelectionCursor(text, range, target, t.select), false); +fn pointMove(tab: u16, t: *Text, text: []const u8, range: modal.Selection, target: usize) void { + t.setRange(tab, text, 0, modal.moveSelectionCursor(text, range, target, t.select), false); } /// word motions select their traversed span (extend mode: head only) -fn wordMove(t: *Text, text: []const u8, range: modal.Selection, cnt: usize, target: modal.WordTarget) void { +fn wordMove(tab: u16, t: *Text, text: []const u8, range: modal.Selection, cnt: usize, target: modal.WordTarget) void { const wr = modal.moveWord(text, range, cnt, target); const res = if (t.select) modal.moveSelectionCursor(text, range, modal.selectionCursor(text, wr), true) else wr; - t.setRange(text, 0, res, false); + t.setRange(tab, text, 0, res, false); } /// f/t/F/T: anchor at the old cursor cell, head on the hit (not found: no move) -fn findMove(t: *Text, text: []const u8, range: modal.Selection, ch: u21, kind: modal.Normal.Find, cnt: usize) void { +fn findMove(tab: u16, t: *Text, text: []const u8, range: modal.Selection, ch: u21, kind: modal.Normal.Find, cnt: usize) void { const cur = modal.selectionCursor(text, range); const target = modal.findTarget(text, cur, ch, kind, cnt) orelse return; const res = if (t.select) modal.moveSelectionCursor(text, range, target, true) else modal.moveSelectionCursor(text, .{ .anchor = cur, .head = cur }, target, true); - t.setRange(text, 0, res, false); + t.setRange(tab, text, 0, res, false); } /// The file pane whose text `text` is, when `t` is its body: its rows are @@ -859,20 +859,20 @@ inline fn filePane(t: *Text, text: []const u8) ?*const Pane { /// j/k (`width` 0: a line is one row) and gj/gk (the rows a body `width` /// cells wide wraps a line into): sticky goal column, clamped onto short /// lines' newline. -fn verticalMove(t: *Text, text: []const u8, range: modal.Selection, down: bool, cnt: usize, width: usize) void { +fn verticalMove(tab: u16, t: *Text, text: []const u8, range: modal.Selection, down: bool, cnt: usize, width: usize) void { const cur = modal.selectionCursor(text, range); const pos = File.textPosition(t, text, cur); const last_row = File.textLineCount(t, text) - 1; var row = pos.row; var line = File.textLine(t, text, row); - var vrow = File.visualRow(line, pos.col, width); + var vrow = File.visualRow(tab, line, pos.col, width); const shown = filePane(t, text); const goal: usize = if (t.sticky_col >= 0) @intCast(t.sticky_col) else if (shown) |fp| - @intCast(@max(0, File.displayOffset(fp, @intCast(row), @intCast(vrow.start), @intCast(pos.col)))) + @intCast(@max(0, File.displayOffset(tab, fp, @intCast(row), @intCast(vrow.start), @intCast(pos.col)))) else - File.rawDisplayCol(line[vrow.start..vrow.end], pos.col -| vrow.start); + File.rawDisplayCol(tab, line[vrow.start..vrow.end], pos.col -| vrow.start); if (width == 0) { row = if (down) @min(pos.row + @max(1, cnt), last_row) else pos.row -| @max(1, cnt); line = File.textLine(t, text, row); @@ -880,51 +880,51 @@ fn verticalMove(t: *Text, text: []const u8, range: modal.Selection, down: bool, } else for (0..@max(1, cnt)) |_| { if (down) { if (vrow.end < line.len) { - vrow = File.visualRow(line, vrow.end, width); + vrow = File.visualRow(tab, line, vrow.end, width); continue; } if (row == last_row) break; row += 1; line = File.textLine(t, text, row); - vrow = File.visualRow(line, 0, width); + vrow = File.visualRow(tab, line, 0, width); } else { if (vrow.start > 0) { - vrow = File.visualRow(line, vrow.start - 1, width); + vrow = File.visualRow(tab, line, vrow.start - 1, width); continue; } if (row == 0) break; row -= 1; line = File.textLine(t, text, row); - vrow = File.visualRow(line, line.len, width); + vrow = File.visualRow(tab, line, line.len, width); } } // The newline slot is a real cursor position, but the first byte of the // NEXT visual row is not: landing there would read as two rows moved. var target_col: usize = if (shown) |fp| - @intCast(File.byteAtRowDisplay(fp, @intCast(row), @intCast(vrow.start), @intCast(@min(goal, std.math.maxInt(i32))))) + @intCast(File.byteAtRowDisplay(tab, fp, @intCast(row), @intCast(vrow.start), @intCast(@min(goal, std.math.maxInt(i32))))) else - vrow.start + File.rawAtDisplay(line[vrow.start..vrow.end], goal); + vrow.start + File.rawAtDisplay(tab, line[vrow.start..vrow.end], goal); if (vrow.end < line.len and target_col >= vrow.end) target_col = modal.graphemeStart(line, vrow.end - 1); const target = File.textOffset(t, text, .{ .row = row, .col = target_col }); // extend mode never walks onto the empty trailing line (helix) if (t.select and target == text.len and text.len > 0 and text[text.len - 1] == '\n') return; - t.setRange(text, 0, modal.moveSelectionCursor(text, range, target, t.select), false); + t.setRange(tab, text, 0, modal.moveSelectionCursor(text, range, target, t.select), false); t.sticky_col = @intCast(goal); } /// Ctrl-d/u: scroll half a page AND move the cursor by the same rows -fn halfPageMove(t: *Text, text: []const u8, range: modal.Selection, down: bool) void { +fn halfPageMove(tab: u16, t: *Text, text: []const u8, range: modal.Selection, down: bool) void { // a view to move through is a body's; a tag or an answer is all shown if (t.what != .body) return; const w = t.pane() orelse return; const half: i32 = @max(1, @divTrunc(@as(i32, w.rows), 2)); w.scrollBy(if (down) half else -half); - verticalMove(t, text, range, down, @intCast(half), 0); + verticalMove(tab, t, text, range, down, @intCast(half), 0); } /// gt/gb: view-relative rows, col 0, scrolloff clamped (helix goto_window) -fn gotoWindow(t: *Text, text: []const u8, range: modal.Selection, which: enum { top, bottom }, cnt: usize) void { +fn gotoWindow(tab: u16, t: *Text, text: []const u8, range: modal.Selection, which: enum { top, bottom }, cnt: usize) void { // a view to move through is a body's; a tag or an answer is all shown if (t.what != .body) return; const w = t.pane() orelse return; @@ -940,7 +940,7 @@ fn gotoWindow(t: *Text, text: []const u8, range: modal.Selection, which: enum { vline = @max(vline, top + margin); vline = @min(vline, top + last_vis - margin); const row: i32 = std.math.clamp(vline, 0, last_row); - pointMove(t, text, range, File.textLineStart(t, text, @intCast(row))); + pointMove(tab, t, text, range, File.textLineStart(t, text, @intCast(row))); } fn lineStartOrEof(text: []const u8, line: usize) usize { @@ -950,17 +950,17 @@ fn lineStartOrEof(text: []const u8, line: usize) usize { /// helix `x` extend_line_below: full lines incl. the newline, cursor ON /// the last one's '\n'; an already-line-bounded selection grows downward -fn lineSelect(t: *Text, text: []const u8, range: modal.Selection, cnt: usize) void { +fn lineSelect(tab: u16, t: *Text, text: []const u8, range: modal.Selection, cnt: usize) void { const span = Text.rangeLineSpan(text, range); const start = modal.lineStartOffset(text, span.start); const end = lineStartOrEof(text, span.end + 1); const full = @min(range.anchor, range.head) == start and @max(range.anchor, range.head) == end; const head = lineStartOrEof(text, span.end + cnt + @intFromBool(full)); - t.setRange(text, 0, .{ .anchor = start, .head = head }, true); + t.setRange(tab, text, 0, .{ .anchor = start, .head = head }, true); } /// helix `X` extend_to_line_bounds (direction kept) -fn lineBoundsSelect(t: *Text, text: []const u8, range: modal.Selection) void { +fn lineBoundsSelect(tab: u16, t: *Text, text: []const u8, range: modal.Selection) void { const span = Text.rangeLineSpan(text, range); const start = modal.lineStartOffset(text, span.start); const end = lineStartOrEof(text, span.end + 1); @@ -968,11 +968,11 @@ fn lineBoundsSelect(t: *Text, text: []const u8, range: modal.Selection) void { .{ .anchor = end, .head = start } else .{ .anchor = start, .head = end }; - t.setRange(text, 0, r, true); + t.setRange(tab, text, 0, r, true); } /// helix `Alt-x` shrink_to_line_bounds (single-line selections untouched) -fn shrinkSelToLineBounds(t: *Text, text: []const u8, range: modal.Selection) void { +fn shrinkSelToLineBounds(tab: u16, t: *Text, text: []const u8, range: modal.Selection) void { const span = Text.rangeLineSpan(text, range); if (span.start == span.end) return; const from = @min(range.anchor, range.head); @@ -986,7 +986,7 @@ fn shrinkSelToLineBounds(t: *Text, text: []const u8, range: modal.Selection) voi .{ .anchor = end, .head = start } else .{ .anchor = start, .head = end }; - t.setRange(text, 0, r, expl); + t.setRange(tab, text, 0, r, expl); } /// Whether a normal-mode role is the text's alone (`textAction`), or @@ -1023,14 +1023,14 @@ pub fn textAction(e: Editor, t: *Text, a: modal.Normal.Action) edit.Error!void { .goto_file_start, .goto_line => { if (!a.explicit and a.role == .goto_line) return; const to = if (a.explicit) @min(@as(usize, a.count) - 1, maxLine(text)) else 0; - return pointMove(t, text, range, modal.lineStartOffset(text, to)); + return pointMove(e.tab, t, text, range, modal.lineStartOffset(text, to)); }, - .goto_last_line => return pointMove(t, text, range, modal.lineStartOffset(text, maxLine(text))), - .goto_line_start, .line_start => return pointMove(t, text, range, modal.lineStartOffset(text, modal.lineAtOffset(text, cur))), + .goto_last_line => return pointMove(e.tab, t, text, range, modal.lineStartOffset(text, maxLine(text))), + .goto_line_start, .line_start => return pointMove(e.tab, t, text, range, modal.lineStartOffset(text, modal.lineAtOffset(text, cur))), .goto_line_end, .line_end => { const line = modal.lineAtOffset(text, cur); const ls = modal.lineStartOffset(text, line); - return pointMove(t, text, range, @max(ls, modal.prevGrapheme(text, modal.lineEndOffset(text, line)))); + return pointMove(e.tab, t, text, range, @max(ls, modal.prevGrapheme(text, modal.lineEndOffset(text, line)))); }, .goto_first_nonws, .line_first_nonws => { const line = modal.lineAtOffset(text, cur); @@ -1038,18 +1038,18 @@ pub fn textAction(e: Editor, t: *Text, a: modal.Normal.Action) edit.Error!void { const slice = text[ls..modal.lineEndOffset(text, line)]; const nw = modal.firstNonWs(slice); if (nw == slice.len) return; - return pointMove(t, text, range, ls + nw); + return pointMove(e.tab, t, text, range, ls + nw); }, - .goto_line_down => return verticalMove(t, text, range, true, a.count, edit.paneWrapWidth(e, t)), - .goto_line_up => return verticalMove(t, text, range, false, a.count, edit.paneWrapWidth(e, t)), + .goto_line_down => return verticalMove(e.tab, t, text, range, true, a.count, edit.paneWrapWidth(e, t)), + .goto_line_up => return verticalMove(e.tab, t, text, range, false, a.count, edit.paneWrapWidth(e, t)), .goto_column => { const line = modal.lineAtOffset(text, cur); const ls = modal.lineStartOffset(text, line); - return pointMove(t, text, range, ls + modal.graphemeAtColumn(text[ls..modal.lineEndOffset(text, line)], @as(usize, a.count) - 1)); + return pointMove(e.tab, t, text, range, ls + modal.graphemeAtColumn(text[ls..modal.lineEndOffset(text, line)], @as(usize, a.count) - 1)); }, .goto_last_modification => { const at = t.last_edit orelse return; - return pointMove(t, text, range, modal.offsetAt(text, .{ .row = @intCast(@max(0, at.row)), .col = @intCast(@max(0, at.col)) })); + return pointMove(e.tab, t, text, range, modal.offsetAt(text, .{ .row = @intCast(@max(0, at.row)), .col = @intCast(@max(0, at.col)) })); }, .find_char_fwd, .find_char_back, .till_char_fwd, .till_char_back => { t.find_op = switch (a.role) { @@ -1059,14 +1059,14 @@ pub fn textAction(e: Editor, t: *Text, a: modal.Normal.Action) edit.Error!void { else => .till_backward, }; t.find_ch = a.char; - return findMove(t, text, range, a.char, t.find_op.?, a.count); + return findMove(e.tab, t, text, range, a.char, t.find_op.?, a.count); }, .replace_prefix => return edit.normalReplaceChar(e, t, a.char), // `mm` .match_prefix => { const lines = try edit.paneCursorLines(e, t); const mc = modal.matchBracket(lines, modal.positionAt(text, cur)) orelse return; - return pointMove(t, text, range, modal.offsetAt(text, mc)); + return pointMove(e.tab, t, text, range, modal.offsetAt(text, mc)); }, .match_inside, .match_around => return edit.textobjectSelect(e, t, text, a.char, a.role == .match_around), inline .goto_function, .goto_class, .goto_parameter, .goto_comment, .goto_test, .goto_entry, .goto_xml_element => |role| { @@ -1077,16 +1077,16 @@ pub fn textAction(e: Editor, t: *Text, a: modal.Normal.Action) edit.Error!void { .surround_add => return edit.surroundAdd(e, t, a.char), .surround_delete => return edit.surroundDelete(e, t, a.char), .surround_replace => return edit.surroundReplace(e, t, a.from, a.char), - .goto_paragraph => return t.setRange(text, 0, modal.moveParagraph(text, range, a.count, a.forward, t.select), false), + .goto_paragraph => return t.setRange(e.tab, text, 0, modal.moveParagraph(text, range, a.count, a.forward, t.select), false), .add_newline => return edit.addNewline(e, t, a.forward, a.count), .move_left, .move_right => { var target = cur; for (0..a.count) |_| target = if (a.role == .move_left) modal.prevGrapheme(text, target) else modal.nextGrapheme(text, target); - return pointMove(t, text, range, target); + return pointMove(e.tab, t, text, range, target); }, - .move_down => return verticalMove(t, text, range, true, a.count, 0), - .move_up => return verticalMove(t, text, range, false, a.count, 0), - inline .next_word_start, .prev_word_start, .next_word_end, .next_long_word_start, .prev_long_word_start, .next_long_word_end => |role| return wordMove(t, text, range, a.count, @field(modal.WordTarget, @tagName(role))), + .move_down => return verticalMove(e.tab, t, text, range, true, a.count, 0), + .move_up => return verticalMove(e.tab, t, text, range, false, a.count, 0), + inline .next_word_start, .prev_word_start, .next_word_end, .next_long_word_start, .prev_long_word_start, .next_long_word_end => |role| return wordMove(e.tab, t, text, range, a.count, @field(modal.WordTarget, @tagName(role))), .repeat_find => { const kind = t.find_op orelse return; var repeated = range; @@ -1101,7 +1101,7 @@ pub fn textAction(e: Editor, t: *Text, a: modal.Normal.Action) edit.Error!void { moved = true; } if (!moved) return; - return t.setRange(text, 0, repeated, false); + return t.setRange(e.tab, text, 0, repeated, false); }, .insert, .append, .insert_line_start, .insert_line_end, .open_below, .open_above => { const where: edit.InsertAt = switch (a.role) { @@ -1127,17 +1127,17 @@ pub fn textAction(e: Editor, t: *Text, a: modal.Normal.Action) edit.Error!void { } t.cur_pinned = true; }, - .select_line => return lineSelect(t, text, range, a.count), - .select_line_bounds => return lineBoundsSelect(t, text, range), - .shrink_to_line_bounds => return shrinkSelToLineBounds(t, text, range), - .collapse_selection => return t.setRange(text, 0, .{ .anchor = cur, .head = cur }, false), + .select_line => return lineSelect(e.tab, t, text, range, a.count), + .select_line_bounds => return lineBoundsSelect(e.tab, t, text, range), + .shrink_to_line_bounds => return shrinkSelToLineBounds(e.tab, t, text, range), + .collapse_selection => return t.setRange(e.tab, text, 0, .{ .anchor = cur, .head = cur }, false), .flip_selection => { const explicit = t.vsel.active and t.vsel.explicit; - return t.setRange(text, 0, .{ .anchor = range.head, .head = range.anchor }, explicit); + return t.setRange(e.tab, text, 0, .{ .anchor = range.head, .head = range.anchor }, explicit); }, - .select_all => return t.setRange(text, 0, .{ .anchor = 0, .head = text.len }, false), + .select_all => return t.setRange(e.tab, text, 0, .{ .anchor = 0, .head = text.len }, false), .keep_primary_sel => return t.dropSels(), - .copy_sel_below, .copy_sel_above, .remove_primary_sel, .rotate_sel_fwd, .rotate_sel_back, .split_sel_newline, .merge_sels, .merge_consecutive_sels, .trim_sels, .ensure_forward => return multiSelAction(t, text, a.role, a.count), + .copy_sel_below, .copy_sel_above, .remove_primary_sel, .rotate_sel_fwd, .rotate_sel_back, .split_sel_newline, .merge_sels, .merge_consecutive_sels, .trim_sels, .ensure_forward => return multiSelAction(e.tab, t, text, a.role, a.count), .delete => return edit.normalDelete(e, t, true), .delete_noyank => return edit.normalDelete(e, t, false), .change => return edit.normalChange(e, t), @@ -1197,8 +1197,8 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) edit.Error! const cur = modal.selectionCursor(text, range); switch (a.role) { - .goto_view_top => return gotoWindow(t, text, range, .top, a.count), - .goto_view_bottom => return gotoWindow(t, text, range, .bottom, a.count), + .goto_view_top => return gotoWindow(p.settings.tab, t, text, range, .top, a.count), + .goto_view_bottom => return gotoWindow(p.settings.tab, t, text, range, .bottom, a.count), // helix align_view: the cursor's row goes `above` rows down the // view, the middle of an odd one and the upper middle of an even one .view_top, .view_center, .view_bottom => if (t.what == .body) { @@ -1208,21 +1208,21 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) edit.Error! else => @as(i32, pane.rows) - 1, }; pane.scrollBy(t.cur_row - (pane.scroll() + above)); - pane.ensureCursorVisible(); + pane.ensureCursorVisible(p.settings.tab); }, // helix align_view_middle: the cursor's column to the middle of an // unwrapped view .view_middle => if (t.what == .body) { - panes.File.geometry(pane); + panes.File.geometry(p.settings.tab, pane); if (pane.body_wrapped) return; const line = modal.lineAtOffset(text, cur); const slice = text[modal.lineStartOffset(text, line)..modal.lineEndOffset(text, line)]; const w: usize = @intCast(@max(1, @as(i32, pane.cols) - @as(i32, panes.File.gutterWidth(pane)))); - const col = panes.File.rawDisplayCol(slice, @intCast(@max(0, t.cur_col))); - pane.hscroll = @intCast(panes.File.rawAtDisplay(slice, col -| w / 2)); + const col = panes.File.rawDisplayCol(p.settings.tab, slice, @intCast(@max(0, t.cur_col))); + pane.hscroll = @intCast(panes.File.rawAtDisplay(p.settings.tab, slice, col -| w / 2)); }, - .view_scroll_down => if (t.what == .body) return t.scrollViewMove(text, range, 1), - .view_scroll_up => if (t.what == .body) return t.scrollViewMove(text, range, -1), + .view_scroll_down => if (t.what == .body) return t.scrollViewMove(p.settings.tab, text, range, 1), + .view_scroll_up => if (t.what == .body) return t.scrollViewMove(p.settings.tab, text, range, -1), .goto_diagnostic, .goto_diagnostic_end => { // Once a Diagnostics query fed them, the diagnostics are this // text's places: ]d and [d step them as n and N do, ]D and [D @@ -1235,13 +1235,13 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) edit.Error! if (!fed) return p.lspRequest(v.active, .diagnostics, ""); if (a.role == .goto_diagnostic) return set.step(p, pane, a.forward, 1, false); if (set.hits.items.len == 0) return; - set.goTo(pane, if (a.forward) set.hits.items.len - 1 else 0, false); + set.goTo(p.settings.tab, pane, if (a.forward) set.hits.items.len - 1 else 0, false); }, // These four move exactly one viewport unit, whatever the count. - .half_page_down => return halfPageMove(t, text, range, true), - .half_page_up => return halfPageMove(t, text, range, false), - .page_down => return t.scrollViewMove(text, range, @as(i32, pane.rows)), - .page_up => return t.scrollViewMove(text, range, -@as(i32, pane.rows)), + .half_page_down => return halfPageMove(p.settings.tab, t, text, range, true), + .half_page_up => return halfPageMove(p.settings.tab, t, text, range, false), + .page_down => return t.scrollViewMove(p.settings.tab, text, range, @as(i32, pane.rows)), + .page_up => return t.scrollViewMove(p.settings.tab, text, range, -@as(i32, pane.rows)), // s, S and | answer for the text they are pressed in; `/` searches // the body wherever it is pressed, as acme's Look from a tag does. inline .select_regex, .split_regex, .keep_regex, .remove_regex => |role| return startSelRegex(p, pane, t, @field(modal.Normal.RegexMode, @tagName(role)[0 .. @tagName(role).len - "_regex".len])), diff --git a/core/panes.zig b/core/panes.zig index fe57793a..cdc28dba 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -563,8 +563,8 @@ pub const Pane = struct { return pane.surfRow(@as(i32, @intCast(Term.grid(pane.terminal).offset)) + pane.pan); } - pub fn wrapAt(pane: *Pane, vr: i32) struct { line: i32, at: i32, pad: i32 = 0 } { - File.geometry(pane); + pub fn wrapAt(pane: *Pane, tab: u16, vr: i32) struct { line: i32, at: i32, pad: i32 = 0 } { + File.geometry(tab, pane); if (pane.wrap_n > 0 and vr >= 0 and vr < @as(i32, pane.wrap_n)) return .{ .line = pane.wrap_line[@intCast(vr)], .at = pane.wrap_col[@intCast(vr)], .pad = pane.wrap_pad[@intCast(vr)] }; // unwrapped: rows ARE lines, and the byte column a row starts at is the @@ -572,8 +572,8 @@ pub const Pane = struct { return .{ .line = pane.scroll() + vr, .at = pane.hscroll }; } - pub fn wrapRow(pane: *Pane, line: i32, col: i32) struct { row: i32, at: i32, pad: i32 = 0 } { - File.geometry(pane); + pub fn wrapRow(pane: *Pane, tab: u16, line: i32, col: i32) struct { row: i32, at: i32, pad: i32 = 0 } { + File.geometry(tab, pane); if (pane.wrap_n == 0) return .{ .row = line - pane.scroll(), .at = pane.hscroll }; var i: u16 = 0; while (i < pane.wrap_n) : (i += 1) { @@ -614,8 +614,8 @@ pub const Pane = struct { return false; } - pub fn ensureCursorVisible(pane: *Pane) void { - File.geometry(pane); + pub fn ensureCursorVisible(pane: *Pane, tab: u16) void { + File.geometry(tab, pane); const off = pane.scroll(); var in_context = false; // The map is the view's as it is now (File.geometry): an ancestor is @@ -663,14 +663,14 @@ pub const Pane = struct { // Measured from the view's left edge to the caret, never from the // line's start: a 500 KB line was walked from byte 0 at every key // (widths add, so the span alone is exact). - const apart = File.lineDisplayOffset(line, raw_scroll, raw_cur); + const apart = File.lineDisplayOffset(tab, line, raw_scroll, raw_cur); const back: ?i32 = if (apart < hmargin) hmargin else if (apart > w - 1 - hmargin) w - 1 - hmargin else null; if (back) |cols| { // The byte `cols` columns before the caret, looked for from a // few bytes a column back (a grapheme is at most 4 a column). const from = raw_cur -| @as(usize, @intCast(cols)) * 4; - const ahead = File.lineDisplayOffset(line, from, raw_cur) - cols; - pane.hscroll = @intCast(if (ahead <= 0) from else File.byteAtDisplayFrom(line, from, @intCast(ahead))); + const ahead = File.lineDisplayOffset(tab, line, from, raw_cur) - cols; + pane.hscroll = @intCast(if (ahead <= 0) from else File.byteAtDisplayFrom(tab, line, from, @intCast(ahead))); } } } diff --git a/core/replica.zig b/core/replica.zig index e4ed4e0a..8b63ed51 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -778,7 +778,7 @@ pub const Replica = struct { // panes show a line. c.kinds.ops = @splat(null); for (c.panes, 0..) |pslot, at| if (pslot) |pane| if (pane.addon) |s| if (c.kinds.byName(s.nameOf())) |k| { - if (c.kinds.ops[k] == null) c.kinds.ops[k] = pardes.Addon.plainOps(&c.kinds.kinds[k]); + if (c.kinds.ops[k] == null) c.kinds.ops[k] = pardes.Addon.plainOps(&c.kinds.kinds[k], o.distrusted); // Refused (its file not here): the line saying it does not run here. if (c.kinds.ops[k]) |ops| pane.addon = pardes.dump.plainHere(c, at, s, ops) catch s; }; @@ -1060,9 +1060,6 @@ pub const Replica = struct { // was there before is of a grid the deltas since moved on // from (a rollback never brings a terminal's past back). r.core().shell_rows = .{}; - // A tab's width is the process's (config.tab_now), which a - // step that set it (Tab) wrote and the copy does not hold. - pardes.config.tab_now = r.core().settings.tab; } r.applied = 0; // Its views as the copy was taken, or as the last delta set them @@ -3636,28 +3633,30 @@ test "the copy taken for an input of its own stays once the input is confirmed: try std.testing.expectEqual(@as(u32, 1), r.stats.foreign); } -test "a rollback over a Tab it applied puts the process's tab width back as its core has it" { - // config.tab_now is the process's, written by the step that set the - // width (the soak, five clients: a Tab undone left it, and the next - // replayed step measured the files' tabs otherwise). +test "a rollback over a Tab it applied measures tabs as its core has them again" { + // A tab's width is the core's (settings.tab, handed to every width + // function), which the copy holds: once the process's (config.tab_now), + // a Tab undone left it, and the next replayed step measured the files' + // tabs otherwise (the soak, five clients). const gpa = std.testing.allocator; - defer pardes.config.tab_now = pardes.config.tab_width; const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); defer a.deinit(); const first = try gpa.dupe(u8, try a.unit(0, 0)); defer gpa.free(first); const r = try Replica.init(gpa, 1, first, false); defer r.deinit(); - pardes.config.tab_now = r.core().settings.tab; const was = r.core().settings.tab; const msg = try gpa.dupe(u8, try r.input(.{ .command = "Tab 2" })); defer gpa.free(msg); try std.testing.expectEqual(@as(usize, 1), r.applied); - try std.testing.expectEqual(@as(u16, 2), pardes.config.tab_now); + try std.testing.expectEqual(@as(u16, 2), r.core().settings.tab); // The session's own key first: back to the confirmed position. r.confirm(try a.local(.{ .key = .{ .cp = 'l', .text = "l" } })); try std.testing.expectEqual(was, r.core().settings.tab); - try std.testing.expectEqual(was, pardes.config.tab_now); + r.settle(); + r.confirm(try a.take(msg)); + r.settle(); + try agrees(a, r); } test "a delta applied under a speculation outlives its rollback: the terminal stays the authority's newest" { diff --git a/core/surface.zig b/core/surface.zig index efc6d3f3..eb552cf1 100644 --- a/core/surface.zig +++ b/core/surface.zig @@ -211,6 +211,9 @@ pub const Surface = struct { /// bar: draw an insert-style thin cursor instead of the block cursor: ?struct { x: u16, y: u16, bar: bool = false } = null, placements: std.ArrayList(Placement) = .empty, + /// A tab's width in cells, as the core it draws has it (`render` sets + /// it from `settings.tab`). + tab: u16 = config.tab_width, pub fn tagLayers(s: *const Surface) []const Layer { return &s.tag_layers; @@ -301,7 +304,7 @@ pub const Surface = struct { var cp = decoded orelse 0xFFFD; if (cp == '\r') return col; if (cp == '\t') { - const spaces = @min(config.tab_now, end - col); + const spaces = @min(s.tab, end - col); s.fill(col, y, spaces, 1, style); return col + spaces; } diff --git a/core/syntax.zig b/core/syntax.zig index adb0ccfe..f95b745a 100644 --- a/core/syntax.zig +++ b/core/syntax.zig @@ -2118,7 +2118,7 @@ test "tables are the pipe_tables tree-sitter finds" { try std.testing.expectEqual(@as(usize, 5), found.items.len); var t: Tables = .{}; defer t.deinit(std.testing.allocator); - try t.scan(std.testing.allocator, source); + try t.scan(@import("config.zig").tab_width, std.testing.allocator, source); var mine: std.ArrayList([2]u32) = .empty; defer mine.deinit(std.testing.allocator); for (t.list.items) |table| try mine.append(std.testing.allocator, .{ table.first, table.end }); diff --git a/core/tagline.zig b/core/tagline.zig index c5e51f23..e8819eb1 100644 --- a/core/tagline.zig +++ b/core/tagline.zig @@ -97,14 +97,14 @@ pub fn revealHeader(p: *Pardes) void { if (rows > 0 and cur >= v.header_top + rows) v.header_top = cur + 1 - rows; const line = modal.lineSlice(text, cur); const width = layout.tagCapacity(p, if (p.headerColumn()) |c| v.col_w[c] -| TAG_TEXT_INSET else v.screen_w -| TAG_TEXT_INSET); - const col = panes.File.rawDisplayCol(line, @min(@as(usize, @intCast(@max(0, t.cur_col))), line.len)); + const col = panes.File.rawDisplayCol(p.settings.tab, line, @min(@as(usize, @intCast(@max(0, t.cur_col))), line.len)); if (col < v.header_scroll) v.header_scroll = col; if (col >= v.header_scroll + width) v.header_scroll = col -| (width -| 1); - var raw = panes.File.rawAtDisplay(line, v.header_scroll); - v.header_scroll = panes.File.rawDisplayCol(line, raw); + var raw = panes.File.rawAtDisplay(p.settings.tab, line, v.header_scroll); + v.header_scroll = panes.File.rawDisplayCol(p.settings.tab, line, raw); if (width > 0 and col >= v.header_scroll + width) { raw = modal.nextGrapheme(line, raw); - v.header_scroll = panes.File.rawDisplayCol(line, raw); + v.header_scroll = panes.File.rawDisplayCol(p.settings.tab, line, raw); } } @@ -289,7 +289,7 @@ pub const Shown = struct { }; /// `whole` wrapped at `width` display columns. -pub fn wrapTag(arena: std.mem.Allocator, whole: []const u8, width: usize) !Shown { +pub fn wrapTag(tab: u16, arena: std.mem.Allocator, whole: []const u8, width: usize) !Shown { var out: std.ArrayList(u8) = .empty; var soft: std.ArrayList(usize) = .empty; const w = @max(1, width); @@ -302,7 +302,7 @@ pub fn wrapTag(arena: std.mem.Allocator, whole: []const u8, width: usize) !Shown // The grapheme at column w, if the row runs past it: a row's // measure, never the whole rest's (this runs on every step). while (true) { - var cut = panes.File.byteAtDisplay(rest, w); + var cut = panes.File.byteAtDisplay(tab, rest, w); if (cut >= rest.len) break; if (cut == 0) cut = modal.nextGrapheme(rest, 0); try out.appendSlice(arena, rest[0..cut]); @@ -326,7 +326,7 @@ pub fn tagWidth(p: *const Pardes, id: usize) usize { pub fn shownTag(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !Shown { const whole = try tagText(p, arena, pane); const id = panes.paneIdOf(p, pane) orelse return .{ .text = whole, .soft = &.{} }; - return wrapTag(arena, whole, tagWidth(p, id)); + return wrapTag(p.settings.tab, arena, whole, tagWidth(p, id)); } /// Where display column `col` of the tag's shown row `row` puts its @@ -337,18 +337,18 @@ pub fn tagOffsetAt(p: *Pardes, pane: *Pane, row: usize, col: usize) ?modal.Curso const whole = tagText(p, arena, pane) catch return null; const at = row + pane.tag_top; const line = modal.lineSlice(shown.text, at); - const off = modal.lineStartOffset(shown.text, at) + modal.graphemeStart(line, panes.File.rawAtDisplay(line, col)); + const off = modal.lineStartOffset(shown.text, at) + modal.graphemeStart(line, panes.File.rawAtDisplay(p.settings.tab, line, col)); return modal.positionAt(whole, @min(shown.toReal(off), whole.len)); } /// Whether display column `col` of the tag's shown row `row` is on a name /// a click drafts: a saving file's path. -pub fn onName(pane: *Pane, row: usize, col: usize) bool { +pub fn onName(tab: u16, pane: *Pane, row: usize, col: usize) bool { if (row + pane.tag_top != 0) return false; const f = pane.file orelse return false; if (!panes.Output.fileTraits(f.output).saves) return false; const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path; - return col < panes.File.displayWidth(name); + return col < panes.File.displayWidth(tab, name); } /// A key typed into a saving file's path, with the tag's cursor there, @@ -364,7 +364,7 @@ pub fn typedIntoName(p: *Pardes, pane: *Pane, key: pardes.Key) bool { const typed = key.text.len > 0 and !key.ctrl and !key.alt; const inside = if (back) at > 0 and at <= f.path.len else if (forward or typed) at < f.path.len else false; if (!inside) return false; - draftName(p, pane, panes.File.displayWidth(f.path[0..at])); + draftName(p, pane, panes.File.displayWidth(p.settings.tab, f.path[0..at])); edit.handleInsert(p.editor(), &pane.input, key); return true; } @@ -378,7 +378,7 @@ pub fn draftName(p: *Pardes, pane: *Pane, col: usize) void { pane.closePrompt(); pane.prompt = .name; pane.prompt_view = p.live; - pane.input = .{ .what = .input, .own = name, .mode = .insert, .cur_pinned = true, .cur_col = @intCast(@min(name.len, panes.File.rawAtDisplay(name, col))) }; + pane.input = .{ .what = .input, .own = name, .mode = .insert, .cur_pinned = true, .cur_col = @intCast(@min(name.len, panes.File.rawAtDisplay(p.settings.tab, name, col))) }; } /// Commit a drafted buffer name, never a disk rename or write. Keep the @@ -455,7 +455,7 @@ pub fn workspaceBlank(p: *Pardes, col: u16, row: u16, tag_hit: ?pardes.TagHit) b const text = edit.flatSurface(p.editor(), &p.global_tag) catch return false; const scroll: usize = if (v.header != null and p.headerColumn() == null) v.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; + return at >= panes.File.displayWidth(p.settings.tab, modal.lineSlice(text, 0)) + 2; } /// Column and workspace tags are one line, as acme's: a newline typed, @@ -536,7 +536,7 @@ test "a column or workspace tag is one line: a newline in it is a space" { test "a pane tag wraps a long line onto rows, and offsets map both ways" { var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); - const shown = try wrapTag(arena_state.allocator(), "/a/b.txt Del Snarf Undo Put\nMore", 10); + const shown = try wrapTag(config.tab_width, arena_state.allocator(), "/a/b.txt Del Snarf Undo Put\nMore", 10); try std.testing.expectEqualStrings("/a/b.txt D\nel Snarf U\nndo Put\nMore", shown.text); try std.testing.expectEqual(@as(usize, 4), shown.rows()); try std.testing.expectEqual(@as(usize, 10), shown.toReal(11)); // the 'e' of Del diff --git a/core/views.zig b/core/views.zig index ba232ab3..b8698854 100644 --- a/core/views.zig +++ b/core/views.zig @@ -563,7 +563,7 @@ fn cursorTo(p: *Pardes, pane: *Pane, row: i32) void { pane.body.cur_row = row; pane.body.cur_col = 0; pane.body.cur_pinned = true; - pane.ensureCursorVisible(); + pane.ensureCursorVisible(p.settings.tab); p.sync(); } |
