Fix cursor jumping to top when redo #320
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This resolves #226.
Issue:
When pressing
u
after:Prettier
, the cursor stays. (#207) However when pressingCtrl-r
afteru
the cursor won't stay but will jump to the top of the file.Cause:
I'm not sure, but it seems that the cursor position information is lost during
:Prettier
operation.:Prettier
essentially deletes all the contents of the current buffer and writes pre-prettier'ed contents into that buffer.vim-prettier/autoload/prettier/utils/buffer.vim
Lines 17 to 28 in 5e6cca2
When changes happen, Vim stores snapshots including cursor positions before those changes are applied. Then when the user presses
Ctrl-r
, Vim reads the cursor position stored in the snapshot. If the cursor position is in the redo block, the current cursor will move to that cursor position. However if the cursor position is outside the redo block, the current cursor will move to "the first line that actually changed".In vim-prettier's case the cursor position is not in the redo block because all the lines upon one of which the cursor position was located are deleted. Thus the current cursor will move to the top of the file which is the first of the lines where the changes occurred.
Fix:
Change the order of
:Prettier
process:Test Plan
For both Vim 8.2 and Neovim 0.6 check if the cursor jumps to the top of the file.
test.js
const a = 1;
and indent one of these lines::Prettier
u
Ctrl-r