mirror of
https://github.com/hyzendust/KickestEnd.nvim.git
synced 2026-02-15 09:21:12 +01:00
added: smart_split_open function for split windows; so Neovim asks if the user wants to re-open the already open buffer in the current tab as split window or just jump to the existing one
This commit is contained in:
@@ -85,6 +85,63 @@ return {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Smart_open_split for split windows
|
||||||
|
local function smart_open_split(state, direction)
|
||||||
|
local node = state.tree:get_node()
|
||||||
|
if not node then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local path = node:get_id()
|
||||||
|
|
||||||
|
if node.type == 'directory' then
|
||||||
|
state.commands.toggle_node(state, node)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Check if file is open in another tab
|
||||||
|
local open_tab, open_win
|
||||||
|
for _, tab in ipairs(vim.api.nvim_list_tabpages()) do
|
||||||
|
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do
|
||||||
|
local buf = vim.api.nvim_win_get_buf(win)
|
||||||
|
if vim.api.nvim_buf_is_valid(buf) and vim.api.nvim_buf_get_name(buf) == path then
|
||||||
|
open_tab = tab
|
||||||
|
open_win = win
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if open_tab then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if open_tab then
|
||||||
|
local choice = vim.fn.confirm('File is already open in another tab. Open split here anyway?', '&Yes\n&No',
|
||||||
|
2)
|
||||||
|
if choice ~= 1 then
|
||||||
|
-- User chose No → jump to the tab where file is open
|
||||||
|
vim.api.nvim_set_current_tabpage(open_tab)
|
||||||
|
vim.api.nvim_set_current_win(open_win)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
-- Else user chose Yes → continue to open split in current tab
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Open split in current tab
|
||||||
|
if direction == 'v' then
|
||||||
|
state.commands.open_vsplit(state)
|
||||||
|
vim.schedule(function()
|
||||||
|
vim.cmd 'wincmd L'
|
||||||
|
end)
|
||||||
|
else
|
||||||
|
state.commands.open_split(state)
|
||||||
|
vim.schedule(function()
|
||||||
|
vim.cmd 'wincmd J'
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.cmd('edit ' .. vim.fn.fnameescape(path))
|
||||||
|
end
|
||||||
|
|
||||||
require('neo-tree').setup {
|
require('neo-tree').setup {
|
||||||
close_if_last_window = true,
|
close_if_last_window = true,
|
||||||
popup_border_style = 'rounded',
|
popup_border_style = 'rounded',
|
||||||
@@ -101,28 +158,10 @@ return {
|
|||||||
mappings = {
|
mappings = {
|
||||||
['<cr>'] = smart_open,
|
['<cr>'] = smart_open,
|
||||||
['v'] = function(state)
|
['v'] = function(state)
|
||||||
local node = state.tree:get_node()
|
smart_open_split(state, 'h')
|
||||||
if node.type == 'directory' then
|
|
||||||
state.commands.toggle_node(state, node)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local path = node:get_id()
|
|
||||||
state.commands.open_split(state) -- opens horizontal split (top)
|
|
||||||
vim.schedule(function()
|
|
||||||
vim.cmd 'wincmd J' -- move the new split to bottom
|
|
||||||
end)
|
|
||||||
end,
|
end,
|
||||||
['h'] = function(state)
|
['h'] = function(state)
|
||||||
local node = state.tree:get_node()
|
smart_open_split(state, 'v')
|
||||||
if node.type == 'directory' then
|
|
||||||
state.commands.toggle_node(state, node)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local path = node:get_id()
|
|
||||||
state.commands.open_vsplit(state) -- opens vertical split (left)
|
|
||||||
vim.schedule(function()
|
|
||||||
vim.cmd 'wincmd L' -- move the new split to right
|
|
||||||
end)
|
|
||||||
end,
|
end,
|
||||||
['t'] = 'noop',
|
['t'] = 'noop',
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user