From 8cbd23a7dca97d7438e07f494c0592ad7da120f6 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 23:28:40 -0300 Subject: tagline: a tag and a header take the keyboard through one takeKeyboard (the cursor pulled back inside the text, nothing selected or pending, normal mode) where enterTag and enterHeader each ended in their own copy of it Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/tagline.zig | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'src') 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 -- cgit v1.3