From 83c837e1cf39820f275d347e5d65c11e8398e102 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 26 Oct 2022 08:29:33 +0200 Subject: [PATCH] feat: properly calculate layout in case of max_width and wrap --- lua/noice/types/nui.lua | 6 +++--- lua/noice/util/nui.lua | 2 +- lua/noice/view/nui.lua | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lua/noice/types/nui.lua b/lua/noice/types/nui.lua index fa59c4d6..d55e71da 100644 --- a/lua/noice/types/nui.lua +++ b/lua/noice/types/nui.lua @@ -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[]} @@ -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 @@ -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 diff --git a/lua/noice/util/nui.lua b/lua/noice/util/nui.lua index 3d4bee0a..d2e60cb5 100644 --- a/lua/noice/util/nui.lua +++ b/lua/noice/util/nui.lua @@ -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) diff --git a/lua/noice/view/nui.lua b/lua/noice/view/nui.lua index 04345a1a..59675d43 100644 --- a/lua/noice/view/nui.lua +++ b/lua/noice/view/nui.lua @@ -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()