PR: set correct '] mark when pasting chunks
How I found it
Hanging around in issues.
How to solve it
This issue was solved with several lines' change, but I had changed the implementation many times that I pushed about 20+ commits.
When I first pushed some code, @zeertzjq
reviewed and comment some changes. I changed several times between two implementations which differed in the if
branches.
After I finalized changes, @zeertzjq
invited @justinmk
to review. @justinmk
rewised me to change some logic which is the same as the first version implementation.
I was changing between several implementations again and again.
Then I realized that I made a mistake that I didn't write a summary for the logic to make all the reviewers to know why I impl it like this. That's why when different reviewers would argued between those changes before.
Here is the merged version,
--- a/runtime/lua/vim/_editor.lua
+++ b/runtime/lua/vim/_editor.lua
@@ -213,7 +213,7 @@ end
vim.inspect = vim.inspect
do
- local tdots, tick, got_line1, undo_started, trailing_nl = 0, 0, false, false, false
+ local startpos, tdots, tick, got_line1, undo_started, trailing_nl = nil, 0, 0, false, false, false
--- Paste handler, invoked by |nvim_paste()|.
---
@@ -328,7 +328,13 @@ do
-- message when there are zero dots.
vim.api.nvim_command(('echo "%s"'):format(dots))
end
+ if startpos == nil then
+ startpos = vim.fn.getpos("'[")
+ else
+ vim.fn.setpos("'[", startpos)
+ end
if is_last_chunk then
+ startpos = nil
vim.api.nvim_command('redraw' .. (tick > 1 and '|echo ""' or ''))
end
return true -- Paste will not continue if not returning `true`.
What I learnt
- You should summarize why you write it like this when there got several different implementations.
- If you think you are right, you should make a brief and clear summary on your code.