Skip to content

Commit 6331500

Browse files
committed
refactor: move all tree:render calls to a central location
1 parent cf2b356 commit 6331500

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ end
4141

4242
M.close_all_nodes = function(state)
4343
renderer.collapse_all_nodes(state.tree)
44-
state.tree:render()
44+
renderer.redraw(state)
4545
end
4646

4747
M.close_node = function(state, callback)
@@ -58,7 +58,7 @@ M.close_node = function(state, callback)
5858

5959
if target_node and target_node:has_children() then
6060
target_node:collapse()
61-
tree:render()
61+
renderer.redraw(state)
6262
renderer.focus_node(state, target_node:get_id())
6363
end
6464
end
@@ -202,7 +202,7 @@ local open_with_cmd = function(state, open_cmd, toggle_directory)
202202
updated = node:expand()
203203
end
204204
if updated then
205-
tree:render()
205+
renderer.redraw(state)
206206
end
207207
end
208208
else
@@ -240,7 +240,7 @@ end
240240
---@param toggle_directory function The function to call to toggle a directory
241241
---open/closed
242242
M.open_tabnew = function (state, toggle_directory)
243-
open_with_cmd(state, "tabnew", toggle_directory)
243+
open_with_cmd(state, "tabnew", toggle_directory)
244244
end
245245

246246
M.rename = function(state, callback)
@@ -266,7 +266,7 @@ M.toggle_node = function(state, toggle_directory)
266266
updated = node:expand()
267267
end
268268
if updated then
269-
tree:render()
269+
renderer.redraw(state)
270270
end
271271
end
272272
end

lua/neo-tree/sources/filesystem/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ local follow_internal = function(callback, force_show)
8585
end
8686
end
8787
if state_changed then
88-
state.tree:render()
88+
renderer.redraw(state)
8989
end
9090
end
9191
end
@@ -369,7 +369,7 @@ M.toggle_directory = function(state, node)
369369
state.explicitly_opened_directories[node:get_id()] = true
370370
end
371371
if updated then
372-
tree:render()
372+
renderer.redraw(state)
373373
end
374374
end
375375
end

lua/neo-tree/sources/manager.lua

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ M.diagnostics_changed = function(source_name, args)
226226
end
227227
M._for_each_state(source_name, function(state)
228228
state.diagnostics_lookup = args.diagnostics_lookup
229-
if state.path and renderer.window_exists(state) then
230-
state.tree:render()
231-
end
229+
renderer.redraw(state)
232230
end)
233231
end
234232

@@ -256,9 +254,7 @@ M.git_status_changed = function(source_name, args)
256254
M._for_each_state(source_name, function(state)
257255
if utils.is_subpath(args.git_root, state.path) then
258256
state.git_status_lookup = args.git_status
259-
if renderer.window_exists(state) then
260-
state.tree:render()
261-
end
257+
renderer.redraw(state)
262258
end
263259
end)
264260
end
@@ -372,9 +368,7 @@ end
372368
-- rendered.
373369
M.redraw = function(source_name)
374370
M._for_each_state(source_name, function(state)
375-
if state.tree and renderer.window_exists(state) then
376-
state.tree:render()
377-
end
371+
renderer.redraw(state)
378372
end)
379373
end
380374

lua/neo-tree/ui/renderer.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,15 @@ M.position = {
441441
is = { restorable = true },
442442
}
443443

444+
---Redraw the tree without relaoding from the source.
445+
---@param state table State of the tree.
446+
M.redraw = function(state)
447+
if state.tree and M.window_exists(state) then
448+
log.trace("Redrawing tree", state.name, state.id)
449+
state.tree:render()
450+
log.trace(" Redrawing tree done", state.name, state.id)
451+
end
452+
end
444453
---Visit all nodes ina tree recursively and reduce to a single value.
445454
---@param tree table NuiTree
446455
---@param memo any Value that is passed to the accumulator function

0 commit comments

Comments
 (0)