fix(api): consider multibyte characters in get_screen_cursor (cmdline) (#1352)

* fix(api): consider multibyte characters in get_screen_cursor (cmdline)

* style: format with stylua

* test: tell luacheck that it is intended unreachable code
This commit is contained in:
NAKAI Tsuyoshi
2022-12-15 20:27:02 +09:00
committed by GitHub
parent 10b1d11252
commit 8bbaeda725
4 changed files with 24 additions and 7 deletions

View File

@@ -125,7 +125,7 @@ core.on_keymap = function(self, keys, fallback)
}, function()
local ctx = self:get_context()
local word = e:get_word()
if string.sub(ctx.cursor_before_line, - #word, ctx.cursor.col - 1) == word and is_printable then
if string.sub(ctx.cursor_before_line, -#word, ctx.cursor.col - 1) == word and is_printable then
fallback()
else
self:reset()
@@ -381,7 +381,7 @@ core.confirm = function(self, e, option, callback)
-- This logic must be used nvim_buf_set_text.
-- If not used, the snippet engine's placeholder wil be broken.
vim.api.nvim_buf_set_text(0, e.context.cursor.row - 1, e:get_offset() - 1, ctx.cursor.row - 1, ctx.cursor.col - 1, {
e.context.cursor_before_line:sub(e:get_offset())
e.context.cursor_before_line:sub(e:get_offset()),
})
vim.api.nvim_win_set_cursor(0, { e.context.cursor.row, e.context.cursor.col - 1 })
end
@@ -444,7 +444,7 @@ core.confirm = function(self, e, option, callback)
if api.is_insert_mode() then
if false then
--To use complex expansion debug.
vim.pretty_print({
vim.pretty_print({ -- luacheck: ignore
diff_before = diff_before,
diff_after = diff_after,
new_text = new_text,