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

Allow opening floating windows not relative to the cursor #60

Closed
dccsillag opened this issue Feb 20, 2022 · 3 comments
Closed

Allow opening floating windows not relative to the cursor #60

dccsillag opened this issue Feb 20, 2022 · 3 comments

Comments

@dccsillag
Copy link

dccsillag commented Feb 20, 2022

Hello!

I've noticed that an option for opening Aerial as a floating window relative to the cursor was added with issue #23. It would be nice, however, to also support opening a floating window that is not relative to the cursor, akin to Fzf/Telescope.

If I'm not mistaken, this would mean an alternate call to nvim_open_win with relative set to "editor", and with width, height, row and col set in a manner to have some padding.

In terms of adding this to the config, I propose the following: add a field to the float section, relative, which can be either "cursor" or "editor" (and maybe also "buffer" in the future?). If it's "cursor" (the default), then it follows the current logic, reading the row, col, max_height and min_height fields. However, if it's set to "editor", then it should look for padding_x and padding_y fields. The shape of the floating window would then be as follows, where w and h are the width and height of the terminal: width = w - 2*floor(padding_x*w), height = h - 2*floor(padding_y*h), row = floor(padding_y*h), col = floor(padding_x*w).

@stevearc
Copy link
Owner

Added some config options for different relative floats, and made the width/height options more flexible (you can specify percentages, rows/cols, or both). There's an escape hatch in config.float.override that will let you customize any of the values if you want.

Give it a try! Let me know if the defaults make sense. I also had to rework a decent chunk of the existing width calculation logic, so let me know if you find any bugs.

@dccsillag
Copy link
Author

Oops, sorry for the delay, totally thought I had already responded.

Thank you very much! I played around with it a bit, and everything seems to be working. Nice work!

Yeah, the defaults seem pretty reasonable.

(Note: I'm personally using something a bit more customized (in Yuescript):

                override: (conf) ->
                    local stats = vim.api.nvim_list_uis![1]
                    local width = stats.width
                    local height = stats.height - 1 -- to account for the statusline
                    local padding_x = math.floor(0.1 * width)
                    local padding_y = math.floor(0.1 * height)

                    conf.width = width - 2*padding_x
                    conf.height = height - 2*padding_y
                    conf.row = padding_y - 1
                    conf.col = padding_x - 1
                    conf.anchor = "NW"

                    conf

)

@stevearc
Copy link
Owner

stevearc commented Mar 2, 2022

I think that you should be able to get a similar layout with:

require('aerial').setup({
  float = {
    relative = 'editor',
    width = 0.8,
    max_width = 0.8,
    height = 0.8,
    max_height = 0.8,
  }
})

But regardless, glad it's working for you!

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