MunifTanjim / nui.nvim

UI Component Library for Neovim.
MIT License
1.62k stars 57 forks source link

[Bug] Can't set popup border with popup.border:set_text when position and size is not set #311

Closed SuperBo closed 10 months ago

SuperBo commented 10 months ago

Can't set/reset popup border with popup.border:set_text when position is not set. Suppose when using Popup with Layout, user don't need to set position explicitly.

Code to reproduce error:

local popup = NuiPopup {
  enter = true,
  focusable = true,
  -- size = { width=100, height = 20 },
  -- position = "50%", -- if these two line are uncommented, code works properly.
  border = {
    style = "rounded",
    padding = {
      left = 1, right = 1
    },
    text = {
      top = "Top title",
      top_align = "left",
      bottom = NuiText("bottom_border", "FloatFooter"),
      bottom_align = "right",
    }
  },
  win_options = {
    winhighlight = "Normal:Normal,FloatBorder:FloatBorder",
  },
  buf_options = {
    modifiable = true,
  }
}

popup.border:set_text('top', "New top title", 'left')

local layout = NuiLayout(
  {
    position = "50%",
    size = {
      width = 80,
      height = 40,
    },
  },
  NuiLayout.Box({
    NuiLayout.Box(popup, { size = "80%" }),
  }, { dir = "col" })
)

layout:mount()
Screenshot 2023-12-06 at 8 02 35 AM
MunifTanjim commented 10 months ago

So this is trying to set border text before mounting the popup.

~Is there any valid use-case for that?~ 🤔

Should be fixed now.

SuperBo commented 10 months ago

Just for clarification, I created the Popup first, then get information from environments and based on return values of environment, I will change the default value of border.

Thank you for quick fix!