diff options
Diffstat (limited to 'src/modal.zig')
| -rw-r--r-- | src/modal.zig | 21 |
1 files changed, 11 insertions, 10 deletions
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); |
