From 601a5c8a31aaa6c2ce7f20ae7150b1da1ac80e01 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 23:16:01 -0300 Subject: Text, normal, modal: the last f/F/t/T is kept as its Find kind (find_op: ?Find), not as the config character that bound it, and findMove and findTarget take the kind instead of two bools; Text's walked shape changes, so a client and a daemon from either side of this change refuse each other (wire semantics) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/Text.zig | 6 +++--- src/modal.zig | 21 +++++++++++---------- src/normal.zig | 25 +++++-------------------- 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/Text.zig b/src/Text.zig index da4be590..202cc339 100644 --- a/src/Text.zig +++ b/src/Text.zig @@ -86,7 +86,7 @@ last_edit: ?struct { row: i32, col: i32 } = null, reg_wait: bool = false, normal: modal.Normal.State = .{}, /// last f/F/t/T motion, for Alt-. repeat -find_op: u8 = 0, +find_op: ?modal.Normal.Find = null, find_ch: u21 = 0, ed_undo: [terminal.history_max]terminal.Snapshot = undefined, ed_undo_len: usize = 0, @@ -508,9 +508,9 @@ pub fn wordMove(t: *Text, text: []const u8, range: modal.Selection, cnt: usize, } /// f/t/F/T: anchor at the old cursor cell, head on the hit (not found: no move) -pub fn findMove(t: *Text, text: []const u8, range: modal.Selection, ch: u21, fwd: bool, till: bool, cnt: usize) void { +pub fn findMove(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, fwd, till, cnt) orelse return; + const target = modal.findTarget(text, cur, ch, kind, cnt) orelse return; const res = if (t.select) modal.moveSelectionCursor(text, range, target, true) else diff --git a/src/modal.zig b/src/modal.zig index 0054afeb..0a61e920 100644 --- a/src/modal.zig +++ b/src/modal.zig @@ -1659,9 +1659,10 @@ pub fn moveParagraph(text: []const u8, r: Selection, count: usize, fwd: bool, ex /// f/F/t/T target cell. helix find_char: the exclusive (till) search starts /// one further out so repeats make progress; not-found = null (no move). -pub fn findTarget(text: []const u8, cursor: usize, ch: u21, fwd: bool, till: bool, count: usize) ?usize { +pub fn findTarget(text: []const u8, cursor: usize, ch: u21, kind: Normal.Find, count: usize) ?usize { + const till = kind == .till_forward or kind == .till_backward; var left = @max(1, count); - if (fwd) { + if (kind == .forward or kind == .till_forward) { const head = nextGrapheme(text, cursor); var i = if (till) nextGrapheme(text, head) else head; if (i > text.len) return null; @@ -1906,14 +1907,14 @@ test "paragraph selections cross blank lines" { test "find targets count matches and skip adjacent till targets" { const t = "abcabc\n"; - try std.testing.expectEqual(@as(usize, 2), findTarget(t, 0, 'c', true, false, 1).?); - try std.testing.expectEqual(@as(usize, 5), findTarget(t, 0, 'c', true, false, 2).?); - try std.testing.expectEqual(@as(usize, 1), findTarget(t, 0, 'c', true, true, 1).?); + try std.testing.expectEqual(@as(usize, 2), findTarget(t, 0, 'c', .forward, 1).?); + try std.testing.expectEqual(@as(usize, 5), findTarget(t, 0, 'c', .forward, 2).?); + try std.testing.expectEqual(@as(usize, 1), findTarget(t, 0, 'c', .till_forward, 1).?); // till repeat skips the adjacent target: from cell 1, next tc reaches 4 - try std.testing.expectEqual(@as(usize, 4), findTarget(t, 1, 'c', true, true, 1).?); - try std.testing.expectEqual(@as(usize, 3), findTarget(t, 5, 'a', false, false, 1).?); - try std.testing.expectEqual(@as(usize, 4), findTarget(t, 5, 'a', false, true, 1).?); - try std.testing.expectEqual(@as(?usize, null), findTarget(t, 0, 'z', true, false, 1)); + try std.testing.expectEqual(@as(usize, 4), findTarget(t, 1, 'c', .till_forward, 1).?); + try std.testing.expectEqual(@as(usize, 3), findTarget(t, 5, 'a', .backward, 1).?); + try std.testing.expectEqual(@as(usize, 4), findTarget(t, 5, 'a', .till_backward, 1).?); + try std.testing.expectEqual(@as(?usize, null), findTarget(t, 0, 'z', .forward, 1)); } test "extended grapheme boundaries cover combining emoji flag and CJK text" { @@ -2016,7 +2017,7 @@ test "GB3 keeps CR-LF one cluster for every grapheme step" { } test "Unicode find and word motion stay on grapheme boundaries" { - try std.testing.expectEqual(@as(usize, 3), findTarget("\u{e9}x\u{e9}", 0, 'é', true, false, 1).?); + try std.testing.expectEqual(@as(usize, 3), findTarget("\u{e9}x\u{e9}", 0, 'é', .forward, 1).?); const text = "café 世界 ok\n"; const first = moveWord(text, .{ .anchor = 0, .head = 1 }, 1, .next_word_start); diff --git a/src/normal.zig b/src/normal.zig index 48bbe915..ee39531d 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -462,7 +462,7 @@ const KeyState = struct { mode: Text.Mode, select: bool, normal: modal.Normal.State, - find_op: u8, + find_op: ?modal.Normal.Find, find_ch: u21, restore_cursor: bool, reg_wait: bool, @@ -707,22 +707,9 @@ fn executeNormalAction(p: *Pardes, t: *Text, semantic: modal.Normal.Action) void .scroll_up => return t.scrollViewMove(text, range, -1), }, .find => |find| { - const op: u8 = switch (find.kind) { - .forward => @intCast(config.find_char_fwd), - .backward => @intCast(config.find_char_back), - .till_forward => @intCast(config.till_char_fwd), - .till_backward => @intCast(config.till_char_back), - }; - t.find_op = op; + t.find_op = find.kind; t.find_ch = find.char; - return t.findMove( - text, - range, - find.char, - find.kind == .forward or find.kind == .till_forward, - find.kind == .till_forward or find.kind == .till_backward, - find.count, - ); + return t.findMove(text, range, find.char, find.kind, find.count); }, .replace_char => |char| return edit.normalReplaceChar(p, t, char), .match_bracket => { @@ -775,14 +762,12 @@ fn executeNormalAction(p: *Pardes, t: *Text, semantic: modal.Normal.Action) void .next_long_word_end => return t.wordMove(text, range, move.count, .next_long_word_end), }, .repeat_find => |count| { - if (t.find_op == 0) return; - const fwd = t.find_op == config.find_char_fwd or t.find_op == config.till_char_fwd; - const till = t.find_op == config.till_char_fwd or t.find_op == config.till_char_back; + const kind = t.find_op orelse return; var repeated = range; var moved = false; for (0..count) |_| { const cc = modal.selectionCursor(text, repeated); - const target = modal.findTarget(text, cc, t.find_ch, fwd, till, 1) orelse break; + const target = modal.findTarget(text, cc, t.find_ch, kind, 1) orelse break; repeated = if (t.select) modal.moveSelectionCursor(text, repeated, target, true) else -- cgit v1.3