Skip to content

fix: auto_expand_width gets caught in infinite loop and hangs neovim (#624) #627

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

Merged
merged 3 commits into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lua/neo-tree/sources/common/container.lua
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ local merge_content = function(context)
-- * Repeat until all layers have been merged.
-- * Join the left and right tables together and return.
--
local huge_number = 2000
local huge_number = vim.o.columns
local remaining_width = context.auto_expand_width and huge_number or context.container_width
local left, right = {}, {}
local left_width, right_width = 0, 0
Expand Down
9 changes: 7 additions & 2 deletions lua/neo-tree/ui/renderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ local prepare_node = function(item, state)
end
state.longest_width_exact = math.max(
state.longest_width_exact,
vim.api.nvim_strwidth(line:content()) + 1
vim.api.nvim_strwidth(line:content())
)
end

Expand Down Expand Up @@ -934,9 +934,14 @@ render_tree = function(state)
state.window.last_user_width = vim.api.nvim_win_get_width(0)
if state.longest_width_exact > state.window.last_user_width then
log.trace(
string.format("`auto_expand_width: on. Expanding width to %s.", state.longest_width_exact)
string.format("auto_expand_width: on. Expanding width to %s.", state.longest_width_exact)
)
vim.api.nvim_win_set_width(0, state.longest_width_exact)
if state.longest_width_exact > vim.api.nvim_win_get_width(0) then
log.error("Not enough width to expand. Aborting.")
state.longest_width_exact = vim.api.nvim_win_get_width(0)
return
end
state.win_width = state.longest_width_exact
render_tree(state)
end
Expand Down