Fix '}'(MoveParagraphEnd) behaviour to accurately emulate Vim's #4527
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.
What this PR does / why we need it:
This PR makes it so
MoveParagraphEnd
behaves exactly like it does in Vim when it is executed with an operator. It doesn't change the behaviour without an operator, which is already accurate.The current implementation doesn't respect the cursor position, breaks when it is repeated by an operator with a count (only moves a paragraph on an odd number iteration) and doesn't respect the blank line at the end of a paragraph like regular Vim.
I've added two properties to
MoveParagraphEnd
:iteration
: Keeps track of the iteration, this way we know when we're on the last iteration, in which case we want to return the position just before the blank line thatparagraphEnd
represents, so that we accurately emulate Vim's behaviour.isFirstLineWise
: Will betrue
if the command was initiated at the beginning of line. We need this because the}
motion will be repeatedcount
number of times and each time we'll receive theposition
of the previousparagraphEnd
which is the blank line after the EoL of the last line in the paragraph. As you may have noticed, thatposition
would always be at the beginning of the line and not be an accurate representation of where the command was initiated.Which issue(s) this PR fixes
Fixes #4488
The issue was being caused by
isLineWise
beingtrue
, thus resulting inparagraphEnd.getLeftThroughLineBreaks
being returned which when we received it as aposition
on a subsequent iteration of the}
motion meant we were still on the same paragraph, that's why the counts were paired ([1,2] =1, [3,4]=2. [5,6] =3, etc..) and it would only move a paragraph on odd numbers.Special notes for your reviewer:
Any feedback is welcomed and appreciated.