This commit is contained in:
hrsh7th
2021-11-23 19:37:25 +09:00
parent 876dd1a427
commit 9b5d64d906
2 changed files with 8 additions and 7 deletions

View File

@@ -144,9 +144,10 @@ end
---Safe version of vim.str_utfindex
---@param text string
---@param vimindex number
---@param vimindex number|nil
---@return number
misc.to_utfindex = function(text, vimindex)
vimindex = vimindex or #text + 1
return vim.str_utfindex(text, math.max(0, math.min(vimindex - 1, #text)))
end
@@ -155,6 +156,7 @@ end
---@param utfindex number
---@return number
misc.to_vimindex = function(text, utfindex)
utfindex = utfindex or #text
for i = utfindex, 1, -1 do
local s, v = pcall(function()
return vim.str_byteindex(text, i) + 1