aerial.nvim icon indicating copy to clipboard operation
aerial.nvim copied to clipboard

[Feature] Automatically toggle of Aerial windows when switching buffers

Open pidgeon777 opened this issue 3 years ago • 2 comments

Let's imagine a layout with 4 buffers as follows:

image

What I'm trying to achieve, is to automatically open an Aerial window when switching to one of those 4 buffers, in a way such that the aerial window is displayed just at the right (or left) of the selected buffer, without modifying the overall buffer layout.

So, when switching to the orange buffer, Aerial (blue) should be opened and displayed this way:

image

When selecting another buffer (yellow), the previous Aerial window should be closed and opened next to the newly selected buffer:

image

How could this behaviour be achieved?

pidgeon777 avatar Aug 02 '22 08:08 pidgeon777

There are already some pieces of this in place

require('aerial').setup({
  -- Open relative to window, not pinned to the far left/right
  placement_editor_edge = false,
  -- Automatically open aerial when you enter a buffer
  open_automatic = true,
})

The part that's missing is closing aerial when you leave the window. I'll look into this

stevearc avatar Aug 02 '22 15:08 stevearc

The part that's missing is closing aerial when you leave the window. I'll look into this

Thank you 👍

And how should close_behavior be configured instead, to obtain the behaviour I described above?

pidgeon777 avatar Aug 03 '22 07:08 pidgeon777

There isn't a value that does what you want yet. I'm looking into adding support when I have time; I just have extremely limited free time for the next few weeks :(

stevearc avatar Aug 03 '22 15:08 stevearc

Don't worry, we all have our busy schedules, take your time 😉

pidgeon777 avatar Aug 04 '22 07:08 pidgeon777

Quick update: I'm going to be off the grid for about a week. This is been in the pending status for longer than I'd like, but it's still on my todo list and I'll come back to it as soon as I'm able.

stevearc avatar Aug 15 '22 18:08 stevearc

Okay, this request led me down a rabbit hole of refactoring config options to make more sense and be more extensible. I've put up a PR that should provide you with the options that you want. Could you check it out and see if it's working as expected? The config options you'll want to set are:

require('aerial').setup({
    close_automatic_events = {
      "unfocus",
    },
    open_automatic = true,
})

stevearc avatar Aug 27 '22 17:08 stevearc

Hello, how could I test your PR 'installing' it with packer? Currently, the latest commit from the main branch gets downloaded with the basic packer config:

    {
      'stevearc/aerial.nvim',
      config = function()
        require("mine.my-aerial-nvim").config()
      end,
      disable = not lvim.builtin.aerial.active,
    },

pidgeon777 avatar Sep 06 '22 13:09 pidgeon777

You can do this with the branch option:

    {
      'stevearc/aerial.nvim',
      branch = "stevearc-focus",
      config = function()
        require("mine.my-aerial-nvim").config()
      end,
      disable = not lvim.builtin.aerial.active,
    },

stevearc avatar Sep 06 '22 13:09 stevearc

It seems to work ok 👍.

And what should the configuration be if I wanted to do the same as above, but without automatically closing the current buffer symbol panel when unfocusing it?

So that for example, given 4 identical buffers split into 4 window zones, every time I enter one of those zones then the corresponding symbol panel appears next to the buffer, leaving the other symbol panels open.

pidgeon777 avatar Sep 07 '22 12:09 pidgeon777

That would be

require('aerial').setup({
    open_automatic = true,
})

stevearc avatar Sep 07 '22 14:09 stevearc

By doing that it works, but if two or more buffers are the same, then the panel is shown only next to the first buffer which gets the focus first.

It is good behaviour which could be useful in some cases, but would there be a way to enable an option to show a panel for each buffer when focused, even if a symbol panel already exists for it?

pidgeon777 avatar Sep 08 '22 07:09 pidgeon777

Needed to do some additional cleanup post-merging that PR. Should be working for you as expected now

stevearc avatar Sep 09 '22 03:09 stevearc

It works perfectly. Great work! 👍

pidgeon777 avatar Sep 09 '22 13:09 pidgeon777