diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-03-06 06:56:24 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-03-15 18:15:18 +0800 |
commit | 2601e0873ff50ed804487dff00bd27e233709beb (patch) | |
tree | b91bad241e69b129a5289178c89189a698c5b301 /runtime/lua/vim/_editor.lua | |
parent | 9b1e1fbc9f795921afd25ba38be5c79dec8b04d2 (diff) | |
download | rneovim-2601e0873ff50ed804487dff00bd27e233709beb.tar.gz rneovim-2601e0873ff50ed804487dff00bd27e233709beb.tar.bz2 rneovim-2601e0873ff50ed804487dff00bd27e233709beb.zip |
fix(paste): don't move cursor past the end of pasted text in Normal mode
Diffstat (limited to 'runtime/lua/vim/_editor.lua')
-rw-r--r-- | runtime/lua/vim/_editor.lua | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua index 8000730795..8e49b51cec 100644 --- a/runtime/lua/vim/_editor.lua +++ b/runtime/lua/vim/_editor.lua @@ -171,27 +171,34 @@ do vim.api.nvim_input(line1) vim.api.nvim_set_option('paste', false) elseif not is_cmdline then - if phase < 2 and mode:find('^[vV\22sS\19]') then - vim.api.nvim_command([[exe "normal! \<Del>"]]) + if mode:find('^i') or mode:find('^n?t') then -- Insert mode or Terminal buffer vim.api.nvim_put(lines, 'c', false, true) - elseif phase < 2 and not mode:find('^[iRt]') then - vim.api.nvim_put(lines, 'c', true, true) - -- XXX: Normal-mode: workaround bad cursor-placement after first chunk. - vim.api.nvim_command('normal! a') - elseif phase < 2 and mode:find('^R') then + elseif phase < 2 and mode:find('^R') and not mode:find('^Rv') then -- Replace mode + -- TODO: implement Replace mode streamed pasting + -- TODO: support Virtual Replace mode local nchars = 0 for _, line in ipairs(lines) do - nchars = nchars + line:len() + nchars = nchars + line:len() end local row, col = unpack(vim.api.nvim_win_get_cursor(0)) local bufline = vim.api.nvim_buf_get_lines(0, row-1, row, true)[1] local firstline = lines[1] firstline = bufline:sub(1, col)..firstline lines[1] = firstline + -- FIXME: #lines can be 0 lines[#lines] = lines[#lines]..bufline:sub(col + nchars + 1, bufline:len()) vim.api.nvim_buf_set_lines(0, row-1, row, false, lines) - else - vim.api.nvim_put(lines, 'c', false, true) + elseif mode:find('^[nvV\22sS\19]') then -- Normal or Visual or Select mode + if mode:find('^n') then -- Normal mode + vim.api.nvim_put(lines, 'c', true, false) + else -- Visual or Select mode + vim.api.nvim_command([[exe "normal! \<Del>"]]) + vim.api.nvim_put(lines, 'c', false, false) + end + -- put cursor at the end of the text instead of one character after it + vim.fn.setpos('.', vim.fn.getpos("']")) + else -- Don't know what to do in other modes + return false end end if phase ~= -1 and (now - tdots >= 100) then |