folke / flash.nvim

Navigate your code with search labels, enhanced character motions and Treesitter integration
Apache License 2.0
2.22k stars 27 forks source link

feature: Treesitter_search remotely #323

Open rgauselumifi opened 3 months ago

rgauselumifi commented 3 months ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

Hi there,

I love using the treesitter_search functionality without jumping to the location.

Describe the solution you'd like

For instance, it would be great to be able to do 'yR' then select a treesitter object, and have it yank without jumping me to the location, just the way that the 'remote' feature does.

Describe alternatives you've considered

I've tried configuring this, but unless I'm missing something I can't see an option.

Additional context

No response

bluss commented 3 months ago

I think regular remote combined with treesitter search already does this or something similar? yr select location then S select treesitter thing, does that work? Or it could be clarified how this differs.

rgauselumifi commented 2 months ago

I think regular remote combined with treesitter search already does this or something similar? yr select location then S select treesitter thing, does that work? Or it could be clarified how this differs.

hmm, doing this has no effect for me after S is pressed.

bluss commented 2 months ago

It works for me, using the documented/default keymaps nvim 0.9.5

svampkorg commented 2 months ago

I tried yR within same window, and from a different buffer in a window split (lets call it remote buffer) with different result.

If yanking with yR, from the remote buffer, the cursor returns to its original position in its original window after the yank. However, when doing the yR from within the same window, the cursor does not return to its original position, rather it stays at the position I yanked the TS-object from.

So @rgauselumifi what you mean with "_I love using the treesittersearch functionality without jumping to the location.", is that the cursor should return to its original position after the yank, regardless of the yank being from the same window or not?

If that is the case, you can sort of achieve this with @bluss suggestion. However, you need to press S once more after ending up where you want to yank from with yr.

Say you press yr, to use the remote functionallity. You then end up with the cursor where you want to yank, and from there you have to press S once more, to select the TS-object you want to yank. After picking the object, you should end up back with your cursor at the original position and you can just press p to paste the yanked TS-object there.

So yR feels a bit like a shortcut for yr + S, with the difference being that it wont return to its original position unless the yank was being made from a different window.

I too, would love for yR to always work the same way regardless of the yank being from a different window or not.

Here are my keys for S, R and r. Maybe they need adjustments to work the way I want:

        {
            "S",
            mode = { "n", "x", "o" },
            function()
                require("flash").treesitter()
            end,
            desc = "Flash Treesitter",
        },
        {
            "r",
            mode = "o",
            function()
                require("flash").remote()
            end,
            desc = "Remote Flash",
        },
        {
            "R",
            mode = { "o", "x" },
            function()
                require("flash").treesitter_search({
                    remote_op = { restore = true, motion = false },
                })
            end,
            desc = "Treesitter Search",
        },

And here are the options I've set for ts, ts-search and remote. They might also need adjustments:

            treesitter = {
                labels = "abcdefghijklmnopqrstuvwxyz",
                jump = { pos = "range" },
                search = { incremental = false },
                label = { before = true, after = true, style = "inline" },
                highlight = {
                    backdrop = false,
                    matches = false,
                },
            },
            treesitter_search = {
                jump = { pos = "range" },
                search = { multi_window = true, wrap = true, incremental = false },
                remote_op = { restore = true, motion = false },
                label = { before = true, after = true, style = "inline" },
            },
            remote = {
                remote_op = { restore = true, motion = true },
            },