diff options
| author | Jackson Moore <jacksonmoore@tuta.io> | 2026-09-04 17:58:58 +0200 |
|---|---|---|
| committer | Jackson Moore <jacksonmoore@tuta.io> | 2026-09-04 17:58:58 +0200 |
| commit | 16dd01a5fc062d03bda6f530f234d5e65bf3e503 (patch) | |
| tree | 7e7e83d5d6de7e0446ceb3af05e3abca9d56b2f7 /lua | |
| parent | ad24568e6419e41f1462b3efd7c1ffe5ec78247e (diff) | |
Iterate multibyte editor characters incrementally
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/clever_f/text_topology.lua | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/lua/clever_f/text_topology.lua b/lua/clever_f/text_topology.lua index 6afbc26..db4ea3b 100644 --- a/lua/clever_f/text_topology.lua +++ b/lua/clever_f/text_topology.lua @@ -113,14 +113,17 @@ local function nvim_split_segment(segment, result) return end - local count = vim.fn.strchars(segment, true) - for character_index = 0, count - 1 do - local first = vim.fn.byteidx(segment, character_index) - local following = vim.fn.byteidx(segment, character_index + 1) - if first < 0 or following <= first then + local offset = 0 + while offset < #segment do + local match = vim.fn.matchstrpos(segment, "\\m.", offset) + local character = match[1] + local first = match[2] + local following = match[3] + if first ~= offset or following <= first or character == "" then fail("Nvim could not index an editor character", 3) end - result[#result + 1] = segment:sub(first + 1, following) + result[#result + 1] = character + offset = following end end |
