diff options
Diffstat (limited to 'core/edit.zig')
| -rw-r--r-- | core/edit.zig | 96 |
1 files changed, 48 insertions, 48 deletions
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 |
