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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I position the float window on the top right with some padding? #107

Closed
dathinaios opened this issue May 25, 2022 · 11 comments
Closed

Comments

@dathinaios
Copy link

Thank you for making this, it is very useful 馃檪

At the moment the floating window options seem to assume that we would like it placed at the center of the editor, window or at the cursor position. Shouldn't there be an option to position it anywhere? I would like to position it at the top right of the window with some padding. Is there maybe a way to achieve this effect with the override function?

@stevearc
Copy link
Owner

Yes, this should be doable with the override function. Try something like

require('aerial').setup({
  float = {
    relative = "editor",
    override = function(conf)
      local padding = 4
      conf.anchor = 'NE'
      conf.row = padding
      conf.col = vim.o.columns - padding
      return conf
    end,
  }
})

@dathinaios
Copy link
Author

Thank you. It is working well though not with more than one splits as it is not positioned within the buffer window. But not a big issue, I have a toggle mapping to use it when I need it 馃檪

@stevearc
Copy link
Owner

If you want it contained within the current window use relative = 'win'

@dathinaios
Copy link
Author

I did try that but it doesn't work. It still displayes at the top right of the editor. Another approach could be to have the float at a fixed position but refreshing depending on the active buffer.

@stevearc
Copy link
Owner

Oh sorry, you'll also have to change the layout column. Instead of vim.o.columns - padding (which is the width of the entire editor), you'd want vim.api.nvim_win_get_width(0) - padding, which is the width of the current window.

@stevearc
Copy link
Owner

In general, I'd recommend checking out the documentation for :help nvim_open_win. It should explain what the various options do and should help you figure out what you need to tweak to get the layout you want.

@dathinaios
Copy link
Author

It works great:

Aerial-float

For reference:

  float = {
    relative = "win",
    override = function(conf)
      local padding = 1 
      conf.anchor = 'NE'
      conf.row = padding
      conf.col = vim.api.nvim_win_get_width(0) - padding
      return conf
    end,
  },

and the autocommand:

vim.api.nvim_exec( 
[[
    au! WinLeave *.rs AerialCloseAll
]], false)

I needed the autocommand because as you can see in the gif my splits resize automatically and that was messing up the placement. In any case I think this is quite elegant 馃檪

Thank you for the help!

@dathinaios
Copy link
Author

This broke with the last update. I see there is a deprecation TODO related to it in the source code but could I have some help with converting it? 馃槵

@stevearc
Copy link
Owner

stevearc commented Oct 8, 2022

I think this wasn't related to deprecation of anything, but instead was because of a change to when the override function gets called. I've made a tweak to that, but also I've changed the signature to pass in the source window ID. I'd recommend making the following change to your config:

  float = {
    relative = "win",
    override = function(conf, source_winid) -- <- the source_winid is new
      local padding = 1 
      conf.anchor = 'NE'
      conf.row = padding
      conf.col = vim.api.nvim_win_get_width(source_winid) - padding
      return conf
    end,
  },

The reason is using 0 as the window ID will use the current window, but the current window may not actually be the window you want to use for width calculations.

@dathinaios
Copy link
Author

Thank you for the reply, still failing unfortunately with this error:

Screenshot 2022-10-08 at 08 47 25

@dathinaios
Copy link
Author

My mistake, I hadn't updated. Seems to be ok now 馃憤 Thank you for your help 馃檪

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

No branches or pull requests

2 participants