diff options
Diffstat (limited to 'lua/clever_f/text_topology.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 |
