PR: Set Correct '] Mark When Pasting Chunks
Background
I discovered this issue while browsing through the Neovim issue tracker.
Solution Process
Although the final fix only required a few lines of code, the implementation went through many iterations, resulting in 20+ commits during the review process.
Review Iterations
The review process turned out to be more challenging than the bug itself. After submitting my initial implementation, @zeertzjq suggested improvements focusing on the conditional logic structure. I experimented with various if branch arrangements, believing I was moving in the right direction.
When @zeertzjq brought @justinmk into the review, I was confident the code was ready to merge. However, @justinmk proposed a significantly different approach—one that, ironically, resembled my very first implementation. This sparked a cycle where I found myself toggling between different versions, each making sense from a certain perspective but lacking consensus from the reviewers.
The Key Lesson
I eventually realized my mistake: I failed to document the rationale behind my implementation choices. Without a clear explanation of why I implemented it a certain way, different reviewers naturally had different preferences and suggestions. This caused unnecessary back-and-forth discussions.
Final Implementation
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`.
Key Takeaways
-
Document your reasoning: When multiple implementation approaches are possible, always explain why you chose your specific approach. This helps reviewers understand your thought process and reduces unnecessary iteration.
-
Be proactive in communication: If you believe your implementation is correct, provide a clear and concise summary explaining your rationale. This prevents misunderstandings and makes the review process more efficient.