Skip to content

Commit 4689290

Browse files
committed
feat: add window_picker command, closes #221
1 parent 726af14 commit 4689290

File tree

5 files changed

+47
-2
lines changed

5 files changed

+47
-2
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,29 @@ use {
5151
requires = {
5252
"nvim-lua/plenary.nvim",
5353
"kyazdani42/nvim-web-devicons", -- not strictly required, but recommended
54-
"MunifTanjim/nui.nvim"
54+
"MunifTanjim/nui.nvim",
55+
{
56+
-- only needed if you want to use the "open_window_picker" command
57+
's1n7ax/nvim-window-picker',
58+
tag = "1.*",
59+
config = function()
60+
require'window-picker'.setup({
61+
autoselect_one = true,
62+
include_current = false,
63+
filter_rules = {
64+
-- filter using buffer options
65+
bo = {
66+
-- if the file type is one of following, the window will be ignored
67+
filetype = { 'neo-tree', "neo-tree-popup", "notify", "quickfix" },
68+
69+
-- if the buffer type is one of following, the window will be ignored
70+
buftype = { 'terminal' },
71+
},
72+
},
73+
other_win_hl_color = '#e35e4f',
74+
})
75+
end,
76+
}
5577
},
5678
config = function ()
5779
-- Unless you are still migrating, remove the deprecated commands from v1.x
@@ -129,6 +151,7 @@ use {
129151
["S"] = "open_split",
130152
["s"] = "open_vsplit",
131153
["t"] = "open_tabnew",
154+
["w"] = "open_with_window_picker",
132155
["C"] = "close_node",
133156
["a"] = "add",
134157
["A"] = "add_directory",

doc/neo-tree.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ s = open_vsplit: Same as open, but opens in a vertical split.
169169

170170
t = open_tabnew: Same as open, but opens in a new tab.
171171

172+
w = open_with_window_picker: Uses the `window-picker` plugin to select a window
173+
to open the selected node in. Requires that
174+
https://github.com/s1n7ax/nvim-window-picker
175+
be installed.
176+
172177
<bs> = navigate_up: Moves the root directory up one level.
173178

174179
. = set_root: Changes the root directory to the currently

lua/neo-tree/defaults.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ local config = {
184184
["S"] = "open_split",
185185
["s"] = "open_vsplit",
186186
["t"] = "open_tabnew",
187+
["w"] = "open_with_window_picker",
187188
["C"] = "close_node",
188189
["z"] = "close_all_nodes",
189190
["R"] = "refresh",

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,20 @@ M.toggle_directory = function(state, toggle_directory)
281281
M.toggle_node(state, toggle_directory)
282282
end
283283

284+
---Marks potential windows with letters and will open the give node in the picked window.
285+
M.open_with_window_picker = function(state)
286+
local node = state.tree:get_node()
287+
local path = node:get_id()
288+
local success, picker = pcall(require, "window-picker")
289+
if not success then
290+
print("You'll need to install window-picker to use this command: https://github.com/s1n7ax/nvim-window-picker")
291+
return
292+
end
293+
local picked_window_id = picker.pick_window()
294+
if picked_window_id then
295+
vim.api.nvim_set_current_win(picked_window_id)
296+
vim.cmd("edit " .. vim.fn.fnameescape(node.path))
297+
end
298+
end
299+
284300
return M

lua/neo-tree/ui/renderer.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ create_window = function(state)
541541
position = state.current_position,
542542
relative = "editor",
543543
buf_options = {
544-
buftype = "nowrite",
544+
buftype = "nofile",
545545
modifiable = false,
546546
swapfile = false,
547547
filetype = "neo-tree",

0 commit comments

Comments
 (0)