Skip to content

Commit cf78366

Browse files
authored
feat: add window_picker options for split and vsplit commands, closes #314
1 parent 0ea25e2 commit cf78366

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ use {
7777
"kyazdani42/nvim-web-devicons", -- not strictly required, but recommended
7878
"MunifTanjim/nui.nvim",
7979
{
80-
-- only needed if you want to use the "open_window_picker" command
80+
-- only needed if you want to use the commands with "_with_window_picker" suffix
8181
's1n7ax/nvim-window-picker',
8282
tag = "1.*",
8383
config = function()
@@ -187,7 +187,9 @@ use {
187187
["<2-LeftMouse>"] = "open",
188188
["<cr>"] = "open",
189189
["S"] = "open_split",
190+
-- ["S"] = "split_with_window_picker",
190191
["s"] = "open_vsplit",
192+
-- ["s"] = "vsplit_with_window_picker",
191193
["t"] = "open_tabnew",
192194
["w"] = "open_with_window_picker",
193195
["C"] = "close_node",

doc/neo-tree.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ w = open_with_window_picker: Uses the `window-picker` plugin to select a window
174174
https://github.com/s1n7ax/nvim-window-picker
175175
be installed.
176176

177+
split_with_window_picker: Same as `open_with_window_picker` but opens split
178+
in selected node instead.
179+
180+
vsplit_with_window_picker: Same as `open_with_window_picker` but opens
181+
vertical split in selected node instead.
182+
177183
<bs> = navigate_up: Moves the root directory up one level.
178184

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

lua/neo-tree/defaults.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ local config = {
198198
["<2-LeftMouse>"] = "open",
199199
["<cr>"] = "open",
200200
["S"] = "open_split",
201+
-- ["S"] = "split_with_window_picker",
201202
["s"] = "open_vsplit",
203+
-- ["s"] = "vsplit_with_window_picker",
202204
["t"] = "open_tabnew",
203205
["w"] = "open_with_window_picker",
204206
["C"] = "close_node",

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,9 @@ M.toggle_directory = function(state, toggle_directory)
305305
end
306306

307307
---Marks potential windows with letters and will open the give node in the picked window.
308-
M.open_with_window_picker = function(state)
308+
---@param cmd string Command that is used to perform action on picked window
309+
local use_window_picker = function(cmd, state)
309310
local node = state.tree:get_node()
310-
local path = node:get_id()
311311
local success, picker = pcall(require, "window-picker")
312312
if not success then
313313
print(
@@ -318,8 +318,23 @@ M.open_with_window_picker = function(state)
318318
local picked_window_id = picker.pick_window()
319319
if picked_window_id then
320320
vim.api.nvim_set_current_win(picked_window_id)
321-
vim.cmd("edit " .. vim.fn.fnameescape(node.path))
321+
vim.cmd(cmd .. ' ' .. vim.fn.fnameescape(node.path))
322322
end
323323
end
324324

325+
---Marks potential windows with letters and will open the give node in the picked window.
326+
M.open_with_window_picker = function(state)
327+
use_window_picker('edit', state)
328+
end
329+
330+
---Marks potential windows with letters and will open the give node in a split next to the picked window.
331+
M.split_with_window_picker = function(state)
332+
use_window_picker('split', state)
333+
end
334+
335+
---Marks potential windows with letters and will open the give node in a vertical split next to the picked window.
336+
M.vsplit_with_window_picker = function(state)
337+
use_window_picker('vsplit', state)
338+
end
339+
325340
return M

0 commit comments

Comments
 (0)