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

The menu supports dynamic adjustment of text length. #394

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions lua/nui/menu/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,26 @@ end
---@param config? nui_layout_options
function Menu:update_layout(config)
Menu.super.update_layout(self, config)

self._.prepare_item = defaults(self._.prepare_item, make_default_prepare_node(self))
self._.prepare_item = make_default_prepare_node(self)
if self.tree then
if self.winid then
self.tree = Tree({
winid = self.winid,
ns_id = self.ns_id,
nodes = self._.items,
get_node_id = function(node)
return node._id
end,
prepare_node = self._.prepare_item,
})

local pos = vim.api.nvim_win_get_cursor(self.winid)
_.set_buf_options(self.bufnr, { modifiable = true, readonly = false })
vim.api.nvim_buf_set_lines(self.bufnr, 0, -1, false, {})
self.tree:render()
vim.api.nvim_win_set_cursor(self.winid, pos)
end
end
end

function Menu:mount()
Expand Down
Loading