stevearc / dressing.nvim

Neovim plugin to improve the default vim.ui interfaces
MIT License
1.69k stars 32 forks source link

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

Closed queezle42 closed 11 months ago

queezle42 commented 11 months ago

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

System information

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: https://github.com/stevearc/dressing.nvim/blob/39611852fd7bbac117e939a26759bb37361f0c90/lua/dressing/input.lua#L249

Possible fixes include:

stevearc commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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

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