Fix multibyte chars

This commit is contained in:
hrsh7th
2021-11-27 18:52:57 +09:00
parent a86017117b
commit 7b744e0589

View File

@@ -290,7 +290,7 @@ custom_entries_view._insert = setmetatable({
word = word or '' word = word or ''
if api.is_cmdline_mode() then if api.is_cmdline_mode() then
local cursor = api.get_cursor() local cursor = api.get_cursor()
local length = vim.str_utfindex(string.sub(api.get_current_line(), self.offset, cursor[2])) local length = vim.fn.strchars(string.sub(api.get_current_line(), self.offset, cursor[2]), true)
vim.api.nvim_feedkeys(keymap.backspace(length) .. word, 'int', true) vim.api.nvim_feedkeys(keymap.backspace(length) .. word, 'int', true)
else else
if this.pending then if this.pending then
@@ -301,9 +301,10 @@ custom_entries_view._insert = setmetatable({
local release = require('cmp').suspend() local release = require('cmp').suspend()
feedkeys.call('', '', function() feedkeys.call('', '', function()
local cursor = api.get_cursor() local cursor = api.get_cursor()
local length = vim.fn.strchars(string.sub(api.get_current_line(), self.offset, cursor[2]), true)
local keys = {} local keys = {}
table.insert(keys, keymap.t('<Cmd>set indentkeys=<CR>')) table.insert(keys, keymap.t('<Cmd>set indentkeys=<CR>'))
table.insert(keys, keymap.backspace(1 + cursor[2] - self.offset)) table.insert(keys, keymap.backspace(length))
table.insert(keys, word) table.insert(keys, word)
table.insert(keys, keymap.t('<Cmd>set indentkeys=%s<CR>'):format(vim.fn.escape(vim.bo.indentkeys, ' "|\\'))) table.insert(keys, keymap.t('<Cmd>set indentkeys=%s<CR>'):format(vim.fn.escape(vim.bo.indentkeys, ' "|\\')))
feedkeys.call( feedkeys.call(