MagicDuck / grug-far.nvim

Find And Replace plugin for neovim
MIT License
650 stars 18 forks source link

Request for Collapsible Search Results #166

Closed ian-ie closed 1 month ago

ian-ie commented 1 month ago

Hello, while using grug-far, I noticed that the search results display a large amount of information, making it somewhat visually cluttered. I would like to suggest adding a feature to collapse search results, allowing users to expand and collapse specific content as needed. This would greatly enhance the readability and user experience. Thank you for your hard work, and I hope you consider this suggestion!

choovick commented 1 month ago

Do you mean like adding a fold per file? like in VSCode or idea, if there are multiple results you can fold single file.

Else you can just narrow down search using file/path filters.

ian-ie commented 1 month ago

Do you mean like adding a fold per file? like in VSCode or idea, if there are multiple results you can fold single file.

Else you can just narrow down search using file/path filters.

yes!like vscode

MagicDuck commented 1 month ago

I think we can do something here, although the nvim fold API is sort of garbagio 😆

Need some feedback. What do you think of the following? I think the second one, where the file name is not part of the fold looks a bit better, right? The number of folded lines tells you the number of results. Although I don't use folds at all so I might be wrong here and the first one is the more practical usage wise. The idea is that you would use those with the regular fold z... keybindings and we would have an option that would control whether we auto-fold immediately on search or not.

image image
choovick commented 1 month ago

I vote for option 2, as it is more informative, and contains at least one search query result. Would be amazing if this will work with standard z... keybindings. Less api to write this way (not an expert)?

MagicDuck commented 1 month ago

added foldcolumn as well to make it more obvious that there are folds there:

image

Implemented the following options:

  -- folding related options
  folding = {
    -- whether to enable folding
    enabled = true,

    -- sets foldlevel, folds with higher level will be closed.
    -- result matche lines for each file have fold level 1
    -- set it to 0 if you would like to have the results initially collapsed
    -- See :h foldlevel
    foldlevel = 1,

    -- visual indicator of folds, see :h foldcolumn
    -- set to '0' to disable
    foldcolumn = '1',
  },

@ian-ie so for your case, just call grug-far with folding.foldlevel = 0 if you want results collapsed immediately. If you want to collapse / manipulate folds after just use z... keybindings, like for example zM

ian-ie commented 1 month ago

Thank you! Now it's working just as I had hoped!