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

Input windows covers the current line when using NW anchor #106

Closed
queezle42 opened this issue Jul 21, 2023 · 3 comments
Closed

Input windows covers the current line when using NW anchor #106

queezle42 opened this issue Jul 21, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@queezle42
Copy link

Describe the bug
vim.ui.input window (e.g. for LSP rename) covers the cursor / current line when configuring input.anchor = "NW".

System information

  • OS: linux (NixOS)
  • Neovim version: 0.9.1
  • Dressing config:
require("dressing").setup {
  input = {
    insert_only = false,
    anchor = "NW",
    mappings = {
      n = {
        ["<C-k>"] = "HistoryPrev",
        ["<C-j>"] = "HistoryNext",
      },
      i = {
        ["<C-k>"] = "HistoryPrev",
        ["<C-j>"] = "HistoryNext",
      },
    },
  },
}

Screenshots
image
image

Additional context
From :help nvim_open_win:

• bufpos: Places float relative to buffer text (only when
  relative="win"). Takes a tuple of zero-indexed [line,
  column]. `row` and `col` if given are applied relative
  to this position, else they default to:
  • `row=1` and `col=0` if `anchor` is "NW" or "NE"
  • `row=0` and `col=0` if `anchor` is "SW" or "SE" (thus
    like a tooltip near the buffer text).

In input.lua, row is set, so the row=1 offset is lost:

winopt.row = util.calculate_row(config.relative, 1, parent_win)

Possible fixes include:

  • Using bufpos instead of row/col (this seems to be the intended way to position a window relative to buffer text)
  • Not setting row/col when using relative="cursor"
  • Update calculate_row to check the anchor. I did that before fully understanding the alternatives (I'll open a PR).
@queezle42 queezle42 added the bug Something isn't working label Jul 21, 2023
stevearc added a commit that referenced this issue Jul 29, 2023
This was left over from before we had the "override" function. Now, it
doesn't make much sense to set the anchor as an option because so much
of the rest of the layout logic depends on the anchor being the default.
If a user wants to customize the layout, the override function is the
way to do it.
@stevearc
Copy link
Owner

Honestly, the anchor should not even be a config option anymore. It's left over from a time when there were more ways to configure the nvim_open_win by passing in static values. That was brittle and not very flexible, so I added the override function as a config option, which allows you to take the options that dressing calculates and perform whatever mutations you want to it. It's much more flexible, and simpler to boot.

@ehaynes99
Copy link

ehaynes99 commented Aug 7, 2023

I used to use this so that it would display under the cursor. Any idea what I should use now?

{
  input = {
    anchor = 'NW',
    override = function(conf)
      -- display under cursor, not on top of it
      if conf.anchor == 'NW' and (conf.row == nil or conf.row == 0) then
        conf.row = 1
      end
      return conf
    end,
  },
}

image
This seems to work, but not sure if it will break elsewhere...

if (conf.row == nil or conf.row == 0) then
  conf.row = 4
end

@stevearc
Copy link
Owner

stevearc commented Aug 9, 2023

@ehaynes99 you can set the anchor in the override function like so:

      override = function(conf)
        conf.anchor = "NW"
        conf.row = 1
      end

andi1984 added a commit to andi1984/dotfiles that referenced this issue Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants