Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor "last column" calculations #554

Merged
merged 12 commits into from
Nov 16, 2022

Conversation

citizenmatt
Copy link
Member

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:

  • Introduces a 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 value
  • Removes the preOffsetComputation, preMove and postMove hooks in the action handlers. These were mostly used to set and reset the LAST_COLUMN magic value. It is simpler to return these as part of the motion, which reduces the places that set the "last column" value
  • Simplify invalidating and resetting the value. Moving the caret invalidates the set value (handling any changes external to IdeaVim) and the value is only set if it is different to the current location

Only 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).

@AlexPl292 AlexPl292 merged commit 27d1170 into JetBrains:master Nov 16, 2022
@AlexPl292
Copy link
Member

Thank you for the updates! Softwraps are coming, I feel

@citizenmatt
Copy link
Member Author

Getting closer! Maybe one more refactor… 😁

@citizenmatt citizenmatt deleted the refactor/adjusted-offset branch November 16, 2022 09:41
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