Skip to content

Commit 3db3fef

Browse files
committed
fix: error opening file when window.width is not lua number
1 parent aec592b commit 3db3fef

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lua/neo-tree/utils.lua

+15
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,21 @@ M.open_file = function(state, path, open_cmd)
496496
if is_neo_tree_window then
497497
-- Neo-tree must be the only window, restore it's status as a sidebar
498498
local width = M.get_value(state, "window.width", 40, false)
499+
local available_width = vim.api.nvim_win_get_width(0)
500+
if type(width) == "string" then
501+
if width:match("^%d+$") then
502+
width = tonumber(width)
503+
elseif width:match("^%d+%%$") then
504+
local percent = tonumber(width:sub(1, -2)) / 100
505+
width = math.floor(available_width * percent)
506+
else
507+
error("Invalid width: " .. width)
508+
end
509+
elseif type(width) == "function" then
510+
width = math.floor(width())
511+
elseif type(width) ~= "number" then
512+
error("Invalid width type: " .. type(width))
513+
end
499514
local nt = require("neo-tree")
500515
local split_command = "vsplit "
501516
-- respect window position in user config when Neo-tree is the only window

0 commit comments

Comments
 (0)