Skip to content

Commit

Permalink
feat: properly calculate layout in case of max_width and wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Oct 26, 2022
1 parent 0630e94 commit 83c837e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lua/noice/types/nui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
---@field relative? NuiRelative
---@field enter? boolean
---@field timeout? number
---@field min_size? number
---@field max_size? number
---@field buf_options? vim.bo
---@field win_options? vim.wo
---@field close? {events?:string[], keys?:string[]}
Expand All @@ -30,7 +28,7 @@

---@class _.NuiPopupOptions: _.NuiBaseOptions
---@field position { row: number|string, col: number|string}
---@field size { row: number|string, col: number|string}
---@field size { width: number|string, height: number|string, max_width:number, max_height:number}
---@field border? _.NuiBorder
---@field focusable boolean
---@field zindex? number
Expand All @@ -42,6 +40,8 @@

---@class _.NuiSplitOptions: _.NuiBaseOptions
---@field position "top"|"right"|"bottom"|"left"
---@field min_size? number
---@field max_size? number
---@field size number|string

---@class NuiSplitOptions: NuiBaseOptions,_.NuiSplitOptions
Expand Down
2 changes: 1 addition & 1 deletion lua/noice/util/nui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ end

---@param dim {width: number, height:number}
---@param _opts NoiceNuiOptions
---@return NoiceNuiOptions
---@return _.NoiceNuiOptions
function M.get_layout(dim, _opts)
---@type _.NoiceNuiOptions
local opts = M.normalize(_opts)
Expand Down
15 changes: 14 additions & 1 deletion lua/noice/view/nui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,20 @@ function NuiView:hide()
end

function NuiView:get_layout()
return Util.nui.get_layout({ width = self:width(), height = self:height() }, self._opts)
local layout = Util.nui.get_layout({ width = self:width(), height = self:height() }, self._opts)
if self._opts.type == "popup" then
---@cast layout _.NuiPopupOptions
if layout.size and layout.size.width < self:width() and self._opts.win_options and self._opts.win_options.wrap then
local height = 0
for _, m in ipairs(self._messages) do
for _, l in ipairs(m._lines) do
height = height + (math.ceil(l:width() / layout.size.width))
end
end
return Util.nui.get_layout({ width = self:width(), height = height }, self._opts)
end
end
return layout
end

function NuiView:tag()
Expand Down

0 comments on commit 83c837e

Please sign in to comment.