-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Separate jump behavior from increment/decrement #4123
Separate jump behavior from increment/decrement #4123
Conversation
ed9357e
to
48a2ff0
Compare
404c225
to
993d58b
Compare
db28af9
to
db96d60
Compare
db96d60
to
285e151
Compare
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
033ced4
to
1f9d56b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, this fell off of my radar for a while 😅
Since we're deleting so much of both modules here, I wonder if we should pull the increment function for datetimes and the increment function for numbers into just one helix_core::increment
module as datetime
and integer
functions. What do you think? OTOH having separate modules is nice since they're small and well-contained
All good! Sorry to take so long to respond, I was on a bit of a vacation. Either in their own modules or in one module is fine by me. I've left them in their own modules for now as it's nice to have the tests contained per type but if folks want them in the same module that's all good by me! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed a merge commit to resolve conflicts and bring in the changes from #4418.
Thanks for working on this! I like how much this cleaned up and simplified the increment/decrement code 🚀
Hey good stuff! Same person as the greg-enbala, I'll be using this account instead of that one from now on. |
increment/decrement (C-a/C-x) had some buggy behavior where selections could be offset incorrectly or the editor could panic with some edits that changed the number of characters in a number or date. These stemmed from the automatic jumping behavior which attempted to find the next date or integer to increment. The jumping behavior also complicated the code quite a bit and made the behavior somewhat difficult to predict when using many cursors. This change removes the automatic jumping behavior and only increments or decrements when the full text in a range of a selection is a number or date. This simplifies the code and fixes the panics and buggy behaviors from changing the number of characters.
increment/decrement (C-a/C-x) had some buggy behavior where selections could be offset incorrectly or the editor could panic with some edits that changed the number of characters in a number or date. These stemmed from the automatic jumping behavior which attempted to find the next date or integer to increment. The jumping behavior also complicated the code quite a bit and made the behavior somewhat difficult to predict when using many cursors. This change removes the automatic jumping behavior and only increments or decrements when the full text in a range of a selection is a number or date. This simplifies the code and fixes the panics and buggy behaviors from changing the number of characters.
Fixes: #2019
This fixes a couple situations I found that cause undesired behavior when incrementing integers:
Trailing underscores, eg:
9_
. When incrementing can cause an infinite loop.I fixed this by not including trailing underscores in the found character Range. This means the incrementing code can
not care about them. Alternatively we could generate the range as it currently is and make the incrementing code ignore the trailing underscores.
A number that changes width when incrementing eg
-1
to0
or9
to10
can crash.Crux of the problem: When multiple numbers are incremented at the same time, there can be multiple shifts in the document length. For example, selecting all the negative signs in
-1 -1 -1
and incrementing will cause the document to be 3 characters shorter. If you naively kept the selection positions tied to the changes, you'd end up with invalid selections that may be entirely off the end of the resulting document. This PR attempts to solve this problem by keeping a running count of how many characters are added or subtracted per applied change and adjusting the resulting selections accordingly.Notable code structure changes in this PR
NumberIncrementor
renamed toIntegerIncrementor
to more accurately reflect what it does.Incrementor
trait removed.Notable behavior changes in this PR
Incrementing only effects what is directly selected. This means the number of selections will never change and selections don't go searching to the end of the line to find something to increment.
DateTimeIncrementor can now only ever increment the Day if what is selected is a Date, or the minutes if what is selected is a DateTime. This is a consequence of only operating directly on what is currently selected.
Numbers can no longer wrap on increment/decrement. The addition/subtraction is saturating. I made this change as I feel it's surprising behavior.
Happy to change this PR to work however folks want it to, add tests, rename things, change the algorithm, whatever folks think is best for helix. Hope this helps!