diff options
| -rw-r--r-- | src/tagline.zig | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/src/tagline.zig b/src/tagline.zig index 66a037f2..317c1c17 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -225,21 +225,27 @@ pub fn enterTag(p: *Pardes, pane: *Pane) void { t.cur_col = @intCast(cursor.col); t.cur_pinned = true; } - // The text may have changed since (a 9P write, a rename), so the - // remembered cursor is pulled back inside it. It is the cursor that - // is remembered, not a selection. - const rows = modal.cursorLineCount(whole); + takeKeyboard(t, whole); + t.sticky_col = -1; + pane.focus = .tag; +} + +/// A tag or a header taking the keyboard in normal mode: its cursor where +/// it was, pulled back inside `text` (it may have changed since: a 9P +/// write, a rename), and nothing selected or pending. It is the cursor that +/// is remembered, not a selection. +fn takeKeyboard(t: *Text, text: []const u8) void { + const rows = modal.cursorLineCount(text); t.cur_row = @intCast(@min(@as(usize, @intCast(@max(0, t.cur_row))), rows - 1)); - const line = modal.lineSlice(whole, @intCast(t.cur_row)); + const line = modal.lineSlice(text, @intCast(t.cur_row)); t.cur_col = @intCast(modal.graphemeStart(line, @min(line.len, @as(usize, @intCast(@max(0, t.cur_col)))))); + t.cur_pinned = true; t.vsel.active = false; t.nsel = 0; t.select = false; t.restore_cursor = false; - t.sticky_col = -1; t.mode = .normal; t.normal.clear(); - pane.focus = .tag; } /// A pane's tag as it is shown: its lines, each wrapped onto more rows at @@ -407,18 +413,7 @@ pub fn enterHeader(p: *Pardes, column: ?usize) void { p.header_column = column; if (column) |c| p.setActiveColumn(c); const t = focusedHeader(p) orelse return exitHeader(p); - const text = edit.flatSurface(p, t) catch ""; - const rows = modal.cursorLineCount(text); - t.cur_row = @intCast(@min(@as(usize, @intCast(@max(0, t.cur_row))), rows - 1)); - const line = modal.lineSlice(text, @intCast(t.cur_row)); - t.cur_col = @intCast(modal.graphemeStart(line, @min(line.len, @as(usize, @intCast(@max(0, t.cur_col)))))); - t.cur_pinned = true; - t.vsel.active = false; - t.nsel = 0; - t.select = false; - t.restore_cursor = false; - t.mode = .normal; - t.normal.clear(); + takeKeyboard(t, edit.flatSurface(p, t) catch ""); } /// The span a header's selection covers on line `row` of its text, in |
