-
-
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
Prevent a panic when uncommenting a line with only a comment token #5933
Conversation
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.
Nice, catch! A minor cosmetic nit, otherwise this LGTM
f146feb
to
6a2af5d
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.
LGTM, thanks!
helix-core/src/comment.rs
Outdated
if matches!(line_slice.get_char(pos + token_len), Some(c) if c != ' ') { | ||
margin = 0; | ||
if !matches!(line_slice.get_char(pos + token_len), Some(c) if c == ' ') { | ||
margin = 0 |
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.
margin = 0 | |
margin = 0; |
looks like this semicolon got chopped off on accident
Open a new document `test.rs` and type the following: `di//<esc><C-c>` The margin calculation pushes the range out of bounds for the comment marker when there are no characters (newline) after it. thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Char range out of bounds: char range 0..3, Rope/RopeSlice char length 2', ropey-1.6.0/src/rope.rs:546:37 The debug build catches the error in the transaction: thread 'main' panicked at 'attempt to subtract with overflow', helix-core/src/transaction.rs:503:26
6a2af5d
to
d201ced
Compare
Open a new document
test.rs
and type the following:di//<esc><C-c>
The margin calculation pushes the range out of bounds for the comment marker when there are no characters (newline) after it.
thread 'main' panicked at 'called
Result::unwrap()
on anErr
value: Char range out of bounds: char range 0..3,Rope/RopeSlice char length 2', ropey-1.6.0/src/rope.rs:546:37
The debug build catches the error in the transaction: thread 'main' panicked at 'attempt to subtract with overflow',
helix-core/src/transaction.rs:503:26