Skip to content

Commit 9fd08eb

Browse files
authored
fix: auto_expand_width gets caught in infinite loop and hangs neovim, fixes #624 (#627)
1 parent e003910 commit 9fd08eb

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lua/neo-tree/sources/common/container.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ local merge_content = function(context)
187187
-- * Repeat until all layers have been merged.
188188
-- * Join the left and right tables together and return.
189189
--
190-
local huge_number = 2000
190+
local huge_number = vim.o.columns
191191
local remaining_width = context.auto_expand_width and huge_number or context.container_width
192192
local left, right = {}, {}
193193
local left_width, right_width = 0, 0

lua/neo-tree/ui/renderer.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ local prepare_node = function(item, state)
345345
end
346346
state.longest_width_exact = math.max(
347347
state.longest_width_exact,
348-
vim.api.nvim_strwidth(line:content()) + 1
348+
vim.api.nvim_strwidth(line:content())
349349
)
350350
end
351351

@@ -934,9 +934,14 @@ render_tree = function(state)
934934
state.window.last_user_width = vim.api.nvim_win_get_width(0)
935935
if state.longest_width_exact > state.window.last_user_width then
936936
log.trace(
937-
string.format("`auto_expand_width: on. Expanding width to %s.", state.longest_width_exact)
937+
string.format("auto_expand_width: on. Expanding width to %s.", state.longest_width_exact)
938938
)
939939
vim.api.nvim_win_set_width(0, state.longest_width_exact)
940+
if state.longest_width_exact > vim.api.nvim_win_get_width(0) then
941+
log.error("Not enough width to expand. Aborting.")
942+
state.longest_width_exact = vim.api.nvim_win_get_width(0)
943+
return
944+
end
940945
state.win_width = state.longest_width_exact
941946
render_tree(state)
942947
end

0 commit comments

Comments
 (0)