diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 436baf3591b..ec15ae213e4 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -348,6 +348,7 @@ Subsequent calls to setup will replace the previous configuration. resize_window = true, window_picker = { enable = true, + picker = "default", chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", exclude = { filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" }, @@ -999,6 +1000,16 @@ Configuration for various actions. from which you last opened the tree. Type: `boolean`, Default: `true` + *nvim-tree.actions.open_file.window_picker.picker* + Change the default window picker, can be a string `"default"` or a function. + The function should return the window id that will open the node, + or `nil` if an invalid window is picked or user cancelled the action. + Type: `string` | `function`, Default: `"default"` + e.g. s1n7ax/nvim-window-picker plugin: > + window_picker = { + enable = true, + picker = require('window-picker').pick_window, +< *nvim-tree.actions.open_file.window_picker.chars* A string of chars used as identifiers by the window picker. Type: `string`, Default: `"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"` diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 2af6df6bd95..d549f7cb69f 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -640,6 +640,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS resize_window = true, window_picker = { enable = true, + picker = "default", chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", exclude = { filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" }, @@ -699,6 +700,7 @@ local FIELD_OVERRIDE_TYPECHECK = { on_attach = { ["function"] = true, string = true }, sort_by = { ["function"] = true, string = true }, root_folder_label = { ["function"] = true, string = true }, + picker = { ["function"] = true, string = true }, } local function validate_options(conf) diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index 1a88f62e29c..7c450be43b4 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -175,7 +175,11 @@ local function get_target_winid(mode, win_ids) end else -- pick a window - target_winid = pick_win_id() + if type(M.window_picker.picker) == "function" then + target_winid = M.window_picker.picker() + else + target_winid = pick_win_id() + end if target_winid == nil then -- pick failed/cancelled return