|
1 | 1 | local a = vim.api
|
2 | 2 |
|
3 |
| -local lib = require "nvim-tree.lib" |
4 | 3 | local log = require "nvim-tree.log"
|
5 | 4 | local view = require "nvim-tree.view"
|
6 | 5 | local util = require "nvim-tree.utils"
|
@@ -236,96 +235,6 @@ local M = {
|
236 | 235 | custom_keypress_funcs = {},
|
237 | 236 | }
|
238 | 237 |
|
239 |
| -local keypress_funcs = { |
240 |
| - close = view.close, |
241 |
| - close_node = require("nvim-tree.actions.movements").parent_node(true), |
242 |
| - collapse_all = require("nvim-tree.actions.collapse-all").fn, |
243 |
| - expand_all = require("nvim-tree.actions.expand-all").fn, |
244 |
| - copy_absolute_path = require("nvim-tree.actions.copy-paste").copy_absolute_path, |
245 |
| - copy_name = require("nvim-tree.actions.copy-paste").copy_filename, |
246 |
| - copy_path = require("nvim-tree.actions.copy-paste").copy_path, |
247 |
| - copy = require("nvim-tree.actions.copy-paste").copy, |
248 |
| - create = require("nvim-tree.actions.create-file").fn, |
249 |
| - cut = require("nvim-tree.actions.copy-paste").cut, |
250 |
| - dir_up = require("nvim-tree.actions.dir-up").fn, |
251 |
| - first_sibling = require("nvim-tree.actions.movements").sibling(-math.huge), |
252 |
| - full_rename = require("nvim-tree.actions.rename-file").fn(true), |
253 |
| - last_sibling = require("nvim-tree.actions.movements").sibling(math.huge), |
254 |
| - live_filter = require("nvim-tree.live-filter").start_filtering, |
255 |
| - clear_live_filter = require("nvim-tree.live-filter").clear_filter, |
256 |
| - next_diag_item = require("nvim-tree.actions.movements").find_item("next", "diag"), |
257 |
| - next_git_item = require("nvim-tree.actions.movements").find_item("next", "git"), |
258 |
| - next_sibling = require("nvim-tree.actions.movements").sibling(1), |
259 |
| - parent_node = require("nvim-tree.actions.movements").parent_node(false), |
260 |
| - paste = require("nvim-tree.actions.copy-paste").paste, |
261 |
| - prev_diag_item = require("nvim-tree.actions.movements").find_item("prev", "diag"), |
262 |
| - prev_git_item = require("nvim-tree.actions.movements").find_item("prev", "git"), |
263 |
| - prev_sibling = require("nvim-tree.actions.movements").sibling(-1), |
264 |
| - refresh = require("nvim-tree.actions.reloaders").reload_explorer, |
265 |
| - remove = require("nvim-tree.actions.remove-file").fn, |
266 |
| - rename = require("nvim-tree.actions.rename-file").fn(false), |
267 |
| - run_file_command = require("nvim-tree.actions.run-command").run_file_command, |
268 |
| - search_node = require("nvim-tree.actions.search-node").fn, |
269 |
| - toggle_file_info = require("nvim-tree.actions.file-popup").toggle_file_info, |
270 |
| - system_open = require("nvim-tree.actions.system-open").fn, |
271 |
| - toggle_dotfiles = require("nvim-tree.actions.toggles").dotfiles, |
272 |
| - toggle_help = require("nvim-tree.actions.toggles").help, |
273 |
| - toggle_custom = require("nvim-tree.actions.toggles").custom, |
274 |
| - toggle_git_ignored = require("nvim-tree.actions.toggles").git_ignored, |
275 |
| - trash = require("nvim-tree.actions.trash").fn, |
276 |
| -} |
277 |
| - |
278 |
| -function M.on_keypress(action) |
279 |
| - if view.is_help_ui() and action == "close" then |
280 |
| - action = "toggle_help" |
281 |
| - end |
282 |
| - if view.is_help_ui() and action ~= "toggle_help" then |
283 |
| - return |
284 |
| - end |
285 |
| - |
286 |
| - if action == "live_filter" or action == "clear_live_filter" then |
287 |
| - return keypress_funcs[action]() |
288 |
| - end |
289 |
| - |
290 |
| - local node = lib.get_node_at_cursor() |
291 |
| - if not node then |
292 |
| - return |
293 |
| - end |
294 |
| - |
295 |
| - local custom_function = M.custom_keypress_funcs[action] |
296 |
| - local default_function = keypress_funcs[action] |
297 |
| - |
298 |
| - if type(custom_function) == "function" then |
299 |
| - return custom_function(node) |
300 |
| - elseif default_function then |
301 |
| - return default_function(node) |
302 |
| - end |
303 |
| - |
304 |
| - if action == "preview" then |
305 |
| - if node.name == ".." then |
306 |
| - return |
307 |
| - end |
308 |
| - if not node.nodes then |
309 |
| - return require("nvim-tree.actions.open-file").fn("preview", node.absolute_path) |
310 |
| - end |
311 |
| - elseif node.name == ".." then |
312 |
| - return require("nvim-tree.actions.change-dir").fn ".." |
313 |
| - elseif action == "cd" then |
314 |
| - if node.nodes ~= nil then |
315 |
| - require("nvim-tree.actions.change-dir").fn(lib.get_last_group_node(node).absolute_path) |
316 |
| - end |
317 |
| - return |
318 |
| - end |
319 |
| - |
320 |
| - if node.link_to and not node.nodes then |
321 |
| - require("nvim-tree.actions.open-file").fn(action, node.link_to) |
322 |
| - elseif node.nodes ~= nil then |
323 |
| - lib.expand_or_collapse(node) |
324 |
| - else |
325 |
| - require("nvim-tree.actions.open-file").fn(action, node.absolute_path) |
326 |
| - end |
327 |
| -end |
328 |
| - |
329 | 238 | function M.apply_mappings(bufnr)
|
330 | 239 | for _, b in pairs(M.mappings) do
|
331 | 240 | local mapping_rhs = b.cb or nvim_tree_callback(b.action)
|
@@ -454,6 +363,8 @@ function M.setup(opts)
|
454 | 363 | M.mappings = merge_mappings(options.list)
|
455 | 364 | end
|
456 | 365 |
|
| 366 | + require("nvim-tree.actions.dispatch").setup(M.custom_keypress_funcs) |
| 367 | + |
457 | 368 | log.line("config", "active mappings")
|
458 | 369 | log.raw("config", "%s\n", vim.inspect(M.mappings))
|
459 | 370 | end
|
|
0 commit comments