Skip to content

feat: use window_picker for split and vsplit as well #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ use {
"kyazdani42/nvim-web-devicons", -- not strictly required, but recommended
"MunifTanjim/nui.nvim",
{
-- only needed if you want to use the "open_window_picker" command
-- only needed if you want to use the commands with "_with_window_picker" suffix
's1n7ax/nvim-window-picker',
tag = "1.*",
config = function()
Expand Down Expand Up @@ -187,7 +187,9 @@ use {
["<2-LeftMouse>"] = "open",
["<cr>"] = "open",
["S"] = "open_split",
-- ["S"] = "split_with_window_picker",
["s"] = "open_vsplit",
-- ["s"] = "vsplit_with_window_picker",
["t"] = "open_tabnew",
["w"] = "open_with_window_picker",
["C"] = "close_node",
Expand Down
6 changes: 6 additions & 0 deletions doc/neo-tree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ w = open_with_window_picker: Uses the `window-picker` plugin to select a window
https://github.com/s1n7ax/nvim-window-picker
be installed.

split_with_window_picker: Same as `open_with_window_picker` but opens split
in selected node instead.

vsplit_with_window_picker: Same as `open_with_window_picker` but opens
vertical split in selected node instead.

<bs> = navigate_up: Moves the root directory up one level.

. = set_root: Changes the root directory to the currently
Expand Down
2 changes: 2 additions & 0 deletions lua/neo-tree/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ local config = {
["<2-LeftMouse>"] = "open",
["<cr>"] = "open",
["S"] = "open_split",
-- ["S"] = "split_with_window_picker",
["s"] = "open_vsplit",
-- ["s"] = "vsplit_with_window_picker",
["t"] = "open_tabnew",
["w"] = "open_with_window_picker",
["C"] = "close_node",
Expand Down
21 changes: 18 additions & 3 deletions lua/neo-tree/sources/common/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ M.toggle_directory = function(state, toggle_directory)
end

---Marks potential windows with letters and will open the give node in the picked window.
M.open_with_window_picker = function(state)
---@param cmd string Command that is used to perform action on picked window
local use_window_picker = function(cmd, state)
local node = state.tree:get_node()
local path = node:get_id()
local success, picker = pcall(require, "window-picker")
if not success then
print(
Expand All @@ -318,8 +318,23 @@ M.open_with_window_picker = function(state)
local picked_window_id = picker.pick_window()
if picked_window_id then
vim.api.nvim_set_current_win(picked_window_id)
vim.cmd("edit " .. vim.fn.fnameescape(node.path))
vim.cmd(cmd .. ' ' .. vim.fn.fnameescape(node.path))
end
end

---Marks potential windows with letters and will open the give node in the picked window.
M.open_with_window_picker = function(state)
use_window_picker('edit', state)
end

---Marks potential windows with letters and will open the give node in a split next to the picked window.
M.split_with_window_picker = function(state)
use_window_picker('split', state)
end

---Marks potential windows with letters and will open the give node in a vertical split next to the picked window.
M.vsplit_with_window_picker = function(state)
use_window_picker('vsplit', state)
end

return M