fix: changed search_node action to determine correct index (#1022)
This commit is contained in:
committed by
GitHub
parent
61a59ffae1
commit
1b8757e530
@@ -15,40 +15,57 @@ function M.fn()
|
|||||||
input_path
|
input_path
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local function count_visible_nodes(nodes)
|
||||||
|
local visible_nodes = 0
|
||||||
|
for _, node in ipairs(nodes) do
|
||||||
|
visible_nodes = visible_nodes + 1
|
||||||
|
|
||||||
|
if node.open and node.nodes then
|
||||||
|
visible_nodes = visible_nodes + count_visible_nodes(node.nodes)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return visible_nodes
|
||||||
|
end
|
||||||
|
|
||||||
local tree_altered = false
|
local tree_altered = false
|
||||||
|
local found_something = false
|
||||||
|
|
||||||
local function search_node(nodes)
|
local function search_node(nodes)
|
||||||
-- first search for absolute match
|
local index = 0
|
||||||
local index_absolute_match = 0
|
|
||||||
for _, node in ipairs(nodes) do
|
for _, node in ipairs(nodes) do
|
||||||
index_absolute_match = index_absolute_match + 1
|
index = index + 1
|
||||||
|
|
||||||
if absolute_input_path == node.absolute_path then
|
if absolute_input_path == node.absolute_path then
|
||||||
return index_absolute_match
|
found_something = true
|
||||||
|
return index
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
-- if no absolute match in current directory, then search for partial match
|
|
||||||
local index_partial_match = 0
|
|
||||||
for _, node in ipairs(nodes) do
|
|
||||||
index_partial_match = index_partial_match + 1
|
|
||||||
|
|
||||||
if node.nodes then
|
if node.nodes then
|
||||||
local matches = utils.str_find(absolute_input_path, node.absolute_path)
|
-- e.g. user searches for "/foo/bar.txt", than directory "/foo/bar" should not match with filename
|
||||||
|
local matches = utils.str_find(absolute_input_path, node.absolute_path .. '/')
|
||||||
|
|
||||||
if matches then
|
if matches then
|
||||||
|
found_something = true
|
||||||
|
|
||||||
|
-- if node is not open -> open it
|
||||||
if not node.open then
|
if not node.open then
|
||||||
node.open = true
|
node.open = true
|
||||||
TreeExplorer:expand(node)
|
TreeExplorer:expand(node)
|
||||||
tree_altered = true
|
tree_altered = true
|
||||||
end
|
end
|
||||||
|
|
||||||
return index_partial_match + search_node(node.nodes)
|
return index + search_node(node.nodes)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return 0
|
if node.open then
|
||||||
|
index = index + count_visible_nodes(node.nodes)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return index
|
||||||
end
|
end
|
||||||
|
|
||||||
local index = search_node(TreeExplorer.nodes)
|
local index = search_node(TreeExplorer.nodes)
|
||||||
@@ -57,7 +74,7 @@ function M.fn()
|
|||||||
renderer.draw()
|
renderer.draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
if index > 0 and view.is_visible() then
|
if found_something and view.is_visible() then
|
||||||
if TreeExplorer.cwd ~= '/' and not view.View.hide_root_folder then
|
if TreeExplorer.cwd ~= '/' and not view.View.hide_root_folder then
|
||||||
index = index + 1
|
index = index + 1
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user