helix icon indicating copy to clipboard operation
helix copied to clipboard

`mdm` not working on rightmost pair element

Open rockboynton opened this issue 1 year ago • 8 comments

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

rockboynton avatar Oct 01 '24 19:10 rockboynton

It is not just rust files, it can be any file

rockboynton avatar Oct 01 '24 19:10 rockboynton

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.

surround_delete

RoloEdits avatar Oct 02 '24 03:10 RoloEdits

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.

surround_delete

yeah that is what I experience as well, glad I'm not the only one. I swear this used to work properly

rockboynton avatar Oct 02 '24 06:10 rockboynton

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

RoloEdits avatar Oct 03 '24 05:10 RoloEdits

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

rockboynton avatar Oct 03 '24 08:10 rockboynton

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`

RoloEdits avatar Oct 03 '24 22:10 RoloEdits

Can you try https://github.com/helix-editor/helix/pull/10611 ?

woojiq avatar Oct 04 '24 19:10 woojiq

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.

RoloEdits avatar Oct 04 '24 22:10 RoloEdits