diff options
Diffstat (limited to 'core/File.zig')
| -rw-r--r-- | core/File.zig | 174 |
1 files changed, 87 insertions, 87 deletions
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); } |
