summaryrefslogtreecommitdiff
path: root/core/Text.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Text.zig')
-rw-r--r--core/Text.zig28
1 files changed, 14 insertions, 14 deletions
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 ----