Skip to content
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

bug v3: preview with main window should open folds #408

Closed
3 tasks done
lervag opened this issue Apr 2, 2024 · 10 comments
Closed
3 tasks done

bug v3: preview with main window should open folds #408

lervag opened this issue Apr 2, 2024 · 10 comments
Labels

Comments

@lervag
Copy link

lervag commented Apr 2, 2024

Did you check docs and existing issues?

  • I have read all the trouble.nvim docs
  • I have searched the existing issues of trouble.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

v0.10.0-dev-2754+g12240600f5

Operating system/version

Arch Linux

Describe the bug

When I open e.g. the symbols or lsp mode in a file where I have folds, the preview will not open/adjust the folds. I believe this can be fixed by including the window option foldenable = false somewhere, but I'm not exactly sure where.

Notice, I can fix this locally through configuration with

    opts = {
      preview = {
        type = "main",
        wo = {
          foldenable = false,
        },
      },
    -- ...

An additional question: I notice that the entire background of the main view is changed on the preview. Do I understand correctly that this is because the main type of the window is really a floating window in disguise? I tried changing it with the winhighlight option in the wo table, but it seems this is always reset?

Steps To Reproduce

  1. Use standard/default settings.
  2. Open e.g. som Lua file.
  3. Enable folds; e.g. based on markers (for instance with -- vim: fdm=marker as a modeline) and add some folds with -- {{{1.
  4. Open the lsp view with :Trouble lsp focus=true
  5. Notice while navigating that the preview will adjust the main files location, but it will not adjust any folds.

Expected Behavior

I believe the expected behaviour would be to adjust folds e.g. with the zv mapping. Or possibly just disable folds for the preview itself.

Repro

No response

@lervag lervag added the bug v3 label Apr 2, 2024
@lervag
Copy link
Author

lervag commented Apr 2, 2024

An additional question: I notice that the entire background of the main view is changed on the preview. Do I understand correctly that this is because the main type of the window is really a floating window in disguise? I tried changing it with the winhighlight option in the wo table, but it seems this is always reset?

Ah, it seems it comes from here:

elseif opts.type == "main" then
opts.type = "float"
opts.relative = "win"
opts.position = { 0, 0 }
opts.size = { width = 1, height = 1 }
opts.wo.winhighlight = ""

I believe, if winhighlight is empty, then it will use a default of Normal:NormalFloat or something like that for floating windows? I'm curious if the hardcoded value therefore should be something like Normal:Normal instead? Or, at least somehow make it configurable - i.e., don't set it to "" if it is already set by the provided opts table?

@folke
Copy link
Owner

folke commented May 12, 2024

Both issue should be fixed now.

In Trouble v2, the actual main window was used to show the preview buffer, but this could lead to all sorts of weird issues.

In v3, I indeed create a fake floating window on top of the main window.

@folke folke closed this as completed May 12, 2024
@lervag
Copy link
Author

lervag commented May 13, 2024

Thanks! It's more or less fixed now - although one thing is still missing (for me). Both the preview, and the navigation with <cr> on an entry in the :Trouble lsp focus=true view will not adjust the folds. That is, given some file that has folds, I would expect the the preview would use something like zv to ensure that the folds are open at the previewed location. Similarly, when I activate a position with <cr>, I would expect that zv is used after navigating to the location.

I would not mind if this is configurable and "default off", although I would argue that, at least for previewing, opening folds seems like the expected behaviour.

@folke folke reopened this May 13, 2024
@lervag
Copy link
Author

lervag commented May 13, 2024

I think, for the <cr> key map, it may be relatively easy to just write a custom action. I'm looking into that now. But the preview seems less straightforward.

folke added a commit that referenced this issue May 29, 2024
@folke
Copy link
Owner

folke commented May 29, 2024

I just pushed a fix for opening folds after jumping (preview was already fixed).
Would be great if you can confirm!

@lervag
Copy link
Author

lervag commented May 29, 2024

Yes, it seems to work very well and perfectly to my preference; thanks! Would it be possible to have this type of behaviour also for the preview feature?

@folke
Copy link
Owner

folke commented May 29, 2024

It should already do that for preview.
Are you using any fold plugins like ufo or something?

@lervag
Copy link
Author

lervag commented May 30, 2024

Huh, ok. It seems you are right. Sorry. The preview does not have any closed folds.

The reason I was confused is this:

  • I have autopreview off.
  • When I click p, the preview displays more or less as expected.
  • While still inside the Trouble window, I navigate to another entry and press p again. I expected the preview to update to the new location, but instead, the preview is closed and I'm again seeing the original view - which in my case was mostly folded. And that's what confused me.

I can see why we might want p to "toggle" the preview, but I would propose a slight change of behaviour:

  • If no preview, then p starts preview for entry under cursor.
  • If preview exists and we are already previewing the cursor entry, then we disable preview (same behaviour as now).
  • If preview exists but cursor is on a different entry, then we instead update the preview to the new entry.

@folke
Copy link
Owner

folke commented May 30, 2024

To get this exact behavior, you can just toggle auto preview with P.

@lervag
Copy link
Author

lervag commented May 30, 2024

To get this exact behavior, you can just toggle auto preview with P.

Well, yes, that's almost right. I don't really like the auto preview. But fair enough, let's leave it at that. If it becomes too much of an itch I can try and make my own p mapping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants