Make vertical moves with large counts move to the first or last line.#44
Merged
matze merged 4 commits intomatze:masterfrom Jun 22, 2020
Merged
Make vertical moves with large counts move to the first or last line.#44matze merged 4 commits intomatze:masterfrom
matze merged 4 commits intomatze:masterfrom
Conversation
It is a more succinct way to specify that the count defaults to 1.
Instead of having our functions read v:count, have them receive it as a parameter. This will help us to avoid repeating the mistake from matze#42 in the future.
If we vertically move a block using a large step when we are close to the start or the end of the file, move as much as possible (that is, until the first or the last line). This should make the behavior of block moves work the same as line moves. Previously, a block move that attempted to move out of bounds would not move at all.
Previously, if we attempted to make a large line move that would put the line out of bounds it would usually give error E16 (Invalid Address). It would only work if out out of bounds destination was only a single line out before/after the start/end of the file. Now, moving a line vertically by a large step does not produce an error. If the step is too large then the movement is clipped to the start or end of the file.
Contributor
Author
|
Now that I look at it, I think that the problem with the "range" functions that I found was the same one that was discussed in PR #27. |
Owner
|
Sounds good to me 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
While working on my last PR I noticed that sometimes we would get an error if we tried to make a large vertical move, when the count was large enough to send the lines "out of bounds".
When moving a lines, if it was only slightly out of bounds (1 too much) then it would move the line to the end of the file. The main situation where this happens is if we move the last line down by one -- it stays in the same place without giving an error. It also did not give an error if you tried to move the penultimate line down by two -- it would move it down by one, so it became the last line in the file. However, if you try to move the last line down by 2+ or the penultimate line by 3+ it would give an error E16: Invalid Range.
Moving blocks vertically had a similar problem. If the block was at the end of the file and we tried to move down by one it would also do nothing. But if we tried do move the penultimate line by 2 or by 3+ it would not move it at all.
This commit updates the behavior to be more consistent. Large vertical moves now move the line/block to the first or last line of the file, without throwing any errors.