Skip to content

Commit 4db7f70

Browse files
committed
fix: add missing open_with_window_picker command, refactor common command inheritance
1 parent 3633cbb commit 4db7f70

File tree

4 files changed

+18
-32
lines changed

4 files changed

+18
-32
lines changed

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ local manager = require("neo-tree.sources.manager")
88

99
local M = {}
1010

11-
local refresh = utils.wrap(manager.refresh, "git_status")
12-
local redraw = utils.wrap(manager.redraw, "git_status")
11+
local refresh = utils.wrap(manager.refresh, "buffers")
12+
local redraw = utils.wrap(manager.redraw, "buffers")
1313

1414
M.add = function(state)
1515
cc.add(state, refresh)
@@ -27,10 +27,6 @@ M.buffer_delete = function(state)
2727
end
2828
end
2929

30-
M.close_node = cc.close_node
31-
M.close_all_nodes = cc.close_all_nodes
32-
M.close_window = cc.close_window
33-
3430
---Marks node as copied, so that it can be pasted somewhere else.
3531
M.copy_to_clipboard = function(state)
3632
cc.copy_to_clipboard(state, redraw)
@@ -66,11 +62,6 @@ M.navigate_up = function(state)
6662
buffers.navigate(state, parent_path)
6763
end
6864

69-
M.open = cc.open
70-
M.open_split = cc.open_split
71-
M.open_vsplit = cc.open_vsplit
72-
M.open_tabnew = cc.open_tabnew
73-
7465
M.refresh = refresh
7566

7667
M.rename = function(state)
@@ -85,6 +76,6 @@ M.set_root = function(state)
8576
end
8677
end
8778

88-
M.toggle_node = cc.toggle_node
79+
cc._add_common_commands(M)
8980

9081
return M

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ end
1919

2020
local M = {}
2121

22+
---Adds all missing common commands to the given module
23+
---@param to_source_command_module table The commands modeul for a source
24+
M._add_common_commands = function(to_source_command_module)
25+
for name, func in pairs(M) do
26+
if type(name) == "string" and not name:match("^_") then
27+
if not to_source_command_module[name] then
28+
to_source_command_module[name] = func
29+
end
30+
end
31+
end
32+
end
33+
2234
---Add a new file or dir at the current node
2335
---@param state table The state of the source
2436
---@param callback function The callback to call when the command is done. Called with the parent node as the argument.

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ M.clear_filter = function(state)
2323
fs.reset_search(state, true)
2424
end
2525

26-
M.close_all_nodes = cc.close_all_nodes
27-
M.close_node = cc.close_node
28-
M.close_window = cc.close_window
29-
3026
M.copy = function(state)
3127
cc.copy(state, refresh)
3228
end
@@ -45,8 +41,6 @@ M.move = function(state)
4541
cc.move(state, refresh)
4642
end
4743

48-
M.show_debug_info = cc.show_debug_info
49-
5044
---Pastes all items from the clipboard to the current directory.
5145
M.paste_from_clipboard = function(state)
5246
cc.paste_from_clipboard(state, utils.wrap(fs.show_new_children, state))
@@ -115,8 +109,6 @@ M.set_root = function(state)
115109
end
116110
end
117111

118-
M.show_debug_info = cc.show_debug_info
119-
120112
---Toggles whether hidden files are shown or not.
121113
M.toggle_hidden = function(state)
122114
state.filtered_items.visible = not state.filtered_items.visible
@@ -134,4 +126,6 @@ M.toggle_node = function (state)
134126
cc.toggle_node(state, utils.wrap(fs.toggle_directory, state))
135127
end
136128

129+
cc._add_common_commands(M)
130+
137131
return M

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ M.add_directory = function(state)
9898
cc.add_directory(state, refresh)
9999
end
100100

101-
M.close_node = cc.close_node
102-
M.close_all_nodes = cc.close_all_nodes
103-
M.close_window = cc.close_window
104-
105101
---Marks node as copied, so that it can be pasted somewhere else.
106102
M.copy_to_clipboard = function(state)
107103
cc.copy_to_clipboard(state, redraw)
@@ -120,8 +116,6 @@ M.move = function(state)
120116
cc.move(state, redraw)
121117
end
122118

123-
M.show_debug_info = cc.show_debug_info
124-
125119
---Pastes all items from the clipboard to the current directory.
126120
M.paste_from_clipboard = function(state)
127121
cc.paste_from_clipboard(state, refresh)
@@ -131,17 +125,12 @@ M.delete = function(state)
131125
cc.delete(state, refresh)
132126
end
133127

134-
M.open = cc.open
135-
M.open_split = cc.open_split
136-
M.open_vsplit = cc.open_vsplit
137-
M.open_tabnew = cc.open_tabnew
138-
139128
M.refresh = refresh
140129

141130
M.rename = function(state)
142131
cc.rename(state, refresh)
143132
end
144133

145-
M.toggle_node = cc.toggle_node
134+
cc._add_common_commands(M)
146135

147136
return M

0 commit comments

Comments
 (0)