Skip to content

Conversation

@hugomg
Copy link
Contributor

@hugomg hugomg commented Jun 22, 2020

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.

hugomg added 4 commits June 22, 2020 10:34
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.
@hugomg
Copy link
Contributor Author

hugomg commented Jun 22, 2020

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.

@matze
Copy link
Owner

matze commented Jun 22, 2020

Sounds good to me 👍

@matze matze merged commit 54f06c4 into matze:master Jun 22, 2020
@hugomg hugomg deleted the no-E16 branch June 22, 2020 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants