add same_line
and anchored
movements
#10576
Open
+619
−4
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 picks up the stale PR #4204. Big thanks to @mitsuhiko for his PR. Seeing the old changes made it really easy to jump right into the code 😎 👍
This PR adds two kinds of new movement sets:
same_line
andanchored
movement.For more info, check the old PR #4204.
same_line
movementCommands added:
move_same_line_char_left
move_same_line_char_right
extend_same_line_char_left
extend_same_line_char_right
append_mode_same_line
These new commands move cursors, while making them stay in the same line. So if a cursor would wrap around into another line, instead it won't move and stay at its current position.
anchored
movementCommands added:
move_anchored_line_up
move_anchored_line_down
move_anchored_visual_line_up
move_anchored_visual_line_down
extend_anchored_line_up
extend_anchored_line_down
extend_anchored_visual_line_up
extend_anchored_visual_line_down
These new commands move cursors vertically. A cursor will move depending on its position:
Differences to the old PR
append_mode_same_line
(for consistency, as append is more or less move right + insert mode)Remarks
Command / function names
I was not sure about the general naming - e.g.
anchored
I think is used somewhere else in the code in a different context. I guess it would be bad if this somehow collided, so you might want to keep that in mind during review. If anyone spots any ambiguities - I'm always open for improvements :)Helper functions context
I created some functions that are only used locally, e.g.
is_in_visual_empty_line()
. In case you think it makes sense to have some of those in a more common context (core?), I can gladly move them.Unit tests
I struggled a bit for the soft-wrap functionality, the corresponding tests might be too implementation-specific and break in the future, if the soft-wrap functionality is adjusted. Couldn't find a better way, so I hope the tests are okay like this.
Also I skipped the unit tests for
Movement::Extend
, as the functionality is exactly the same as withMovement::Move
.Docs
I don't know if these commands should be documented somewhere, e.g. in the book. If it makes sense, I can write a few describing words.
Only a single setting
If these movements should have only a single setting (i.e. a bool that can be set) then this would probably affect a bit the architecture. Not sure how it would be best to implement it, but I would maybe go for additional values in either
helix_core::Movement
orhelix_core::Direction
.But I think the way it was implemented previously (and still is) allows for quite versatile configuration and fits nice into the existing architecture, so I would prefer it the way it is.