helix
helix copied to clipboard
`mdm` not working on rightmost pair element
Summary
I have a rust import statement, use foo::{bar, baz}; If I place the cursor on the rightmost }, and try to do mdm it doesn't work (error says "Surround pair not found around all cursors") But if I do mmmdm it works (delete the pair with the cursor on the leftmost {
Reproduction Steps
No response
Helix log
No response
Platform
Linux
Terminal Emulator
wezterm 20240203-110809-5046fc22
Installation Method
Nix Flake
Helix Version
helix 24.7, 748a9cf022eb74e96a3697e4b11b2490b1e58f08
It is not just rust files, it can be any file
I've replicated this, but seems to be a bit more nuanced than I thought it would be. When deleting, it works if you select the first bracket open bracket, but trying to do this from the closing one leads to the weird behavior.
I've replicated this, but seems to be a bit more nuanced than I thought it would be. When deleting, it works if you select the first bracket open bracket, but trying to do this from the closing one leads to the weird behavior.
yeah that is what I experience as well, glad I'm not the only one. I swear this used to work properly
Trying to look into this more, and found that when there is no sort, the behavior of the inner pair is reversed, where the opening pair main selection is what deletes the outer pair.
https://github.com/helix-editor/helix/blob/57ec3b7330de3f5a7b37e766a758f13fdf3c0da5/helix-term/src/commands.rs#L5691-L5717
The error is coming from this function:
https://github.com/helix-editor/helix/blob/57ec3b7330de3f5a7b37e766a758f13fdf3c0da5/helix-core/src/surround.rs#L92-L155
I actually started debugging it myself and it looks like the plaintext implementation works, just not the treesitter one. And the find_matching_bracket_fuzzy call in particular is where it returns from the function due to the ? operator. That's where I left off
Interesting, I added this:
pub fn find_nth_closest_pairs_pos(
syntax: Option<&Syntax>,
text: RopeSlice,
range: Range,
skip: usize,
) -> Result<(usize, usize)> {
match syntax {
Some(syntax) => find_nth_closest_pairs_ts(syntax, text, range, skip).map_err(|err| {
log::error!("Error with `find_nth_closest_pairs_ts`");
err
}),
None => find_nth_closest_pairs_plain(text, range, skip).map_err(|err| {
log::error!("Error with `find_nth_closest_pairs_plain`");
err
}),
}
}
Which when replicating the behavior led to:
2024-10-02T21:55:17.193 helix_core::surround [ERROR] Error with `find_nth_closest_pairs_plain`
Can you try https://github.com/helix-editor/helix/pull/10611 ?
I'm still seeing the same behavior as mentioned in this issue. As mentioned above, I seem to be triggering the error at the bottom of find_nth_closest_pairs_plain, but @rockboynton has found issue with the tree-sitter version. Would be great if we could nail down where the actual error is coming from. Then figure out if the logic is faulty or if the parameters being passed in are not not upholding some constraint.