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.
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
Add command to inc/dec number under cursor #1027
Add command to inc/dec number under cursor #1027
Changes from 2 commits
d6b2d00
2bd252f
f78bb73
6484ff9
82a65d5
e2571fb
f6c8fba
e424180
f3d88cd
483c0d5
95a02b7
52e3de3
66c4920
d3d7729
4754b49
7f18e9a
df30836
f4825e4
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 don't understand what does this do. Can you please put a comment here? Is it because the integer may be too large? Or is it to handle the cast?
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.
In Vim's implementation, decrementing 0x0 results in 0xffffffffffffffff, which is -1 for i64. However, if we try to parse that with i64::from_str_radix we get an error because it tries to parse it as a positive number and overflows. If I parse it as an i128, I can cast it to i64 to get the negative value.
This check just makes sure the number fits in an i64. You may be wondering why I didn't use
try_from
to convert to i64, and the reason is it wouldn't work for parsing negative numbers that aren't base 10.but
This version will get a
TryFromIntError
error because the original i128 is actually a positive number that's too large to fit in an i64.Can you think of a better way to handle this, or do you think adding a comment is the best option?
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.
Maybe the best thing to do here is change the behavior from what Vim does.
Vim treats
0xFFFFFFFFFFFFFFFF
as-1
, because that's the bit pattern of -1 for a 64 bit two-complement integer. Vim only handles the minus sign for base 10 numbers.So in Vim
-0x01
gets incremented to-0x02
instead of0x00
because it ignores the minus sign. We could make helix only interpret the number as negative if it has a minus sign.Also in Vim
0x00
gets decremented to0xffffffffffffffff
, but we could have helix decrement it to-0x01
.But this would also mean that
0xffffffffffffffff
would be too large and wouldn't be parsed as an i64.What do you think?
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 think the easiest way here might be just store it as i128 but either way, this is already merged so it should be good.