-
-
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
Fix panic in min_width_1/grapheme_aligned when Range extends past bounds #2090
Conversation
… the slice length.
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.
This seems like a reasonable place to fix this. But I am a little concerned that clamping like this might end up masking out-of-bounds bugs that should otherwise be fixed.
For example, although I haven't looked closely at all, there's a chance that this change is actually just masking the bug you're running into, which may also manifest in other ways than out-of-bounds.
helix-core/src/selection.rs
Outdated
// 4. Ranges are sorted by their position in the text. | ||
pub fn ensure_invariants(self, text: RopeSlice) -> Self { |
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.
If we're going to add the check here, let's add it to the list of checks in the comment as well.
/// they are set to the length of the slice. | ||
#[must_use] | ||
#[inline] | ||
pub fn clamp_range(&self, slice: RopeSlice) -> Self { |
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.
Thumbs up here. This is a good method to have, regardless of whether we incorporate it into ensure_invariants()
or not.
This is a great point - being unfamiliar with the codebase I'm not exactly sure how many places use I did a little extra digging and from what I can tell, the cause of the panic can manifest in a few ways, but it's due to the view's It seems like this could feasibly be addressed when returning the I did however push an update to the comment of |
Adding @archseer since I think he had some thoughts about this. |
Yeah so the issue here is that the jumplists aren't updated as documents change, so a selection on the jumplist can become invalid if you delete enough of the document. The solution would be to also map any external references when calling Could you also log a warning if clamping happened? I'd also like us to panic in debug mode (potentially with extra checks) so these cases can be caught in tests. kakoune for example has a few methods that do checking in debug: |
Fixed in #4186 |
This change addresses a bug when using
jump_forward
/jump_backwards
, when the saved selection in the jumplist contains a range that extends past the end of the document.The easiest way to reproduce this bug is to write "hi", save the space after "hi" to the jumplist via ctrl+s, delete everything, use ctrl+o to jump and you receive
because the range extends past the slice length.
I am very unfamiliar with this codebase, and I did add some tests and can confirm that after my changes, the use case I described now no longer panics, but if this is not the correct place to implement this bounds checking, please let me know.