Refactor "last column" calculations #554
Merged
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.
This PR refactors how IdeaVim handles tracking the "last column" value. This value is the intended location of the caret, when that value might be adjusted before actually moving the caret. For example, if the caret is on a long line and moved to a shorter line, the original column value is stored as the "last column" (intended) value, so that the original column can be used when moving back to a longer line. Similarly, it can be set to the
LAST_COLUMN
magic value by the$
command to always put the caret at the end of the line, regardless of length.This PR:
Motion.AdjustedOffset
that can be returned from motion action handlers and helpers. This allows the handlers and helpers to calculate the adjustment, which will be important for soft wrap support. The base motion action handler understands this new type and will move the caret and update the saved valuepreOffsetComputation
,preMove
andpostMove
hooks in the action handlers. These were mostly used to set and reset theLAST_COLUMN
magic value. It is simpler to return these as part of the motion, which reduces the places that set the "last column" valueOnly handlers that use
Motion
(i.e. motion action handlers) get this automatic setting of "last column". Other handlers such as operators still have to set the value manually, as before. However, they need to be careful to reset the value if the caret is moved as part of the operation (e.g. delete will move the caret, so the value needs to be stored in a variable before deleting, and reset before moving).