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