This commit is contained in:
committed by
GitHub
parent
23a564f1cd
commit
c4ac723a83
@@ -179,32 +179,34 @@ local function open_in_new_window(filename, mode, win_ids)
|
|||||||
if not target_winid then
|
if not target_winid then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local do_split = mode == "split" or mode == "vsplit"
|
|
||||||
local split_side = (view.View.side == "right") and "aboveleft" or "belowright"
|
local create_new_window = #api.nvim_list_wins() == 1
|
||||||
|
local new_window_side = (view.View.side == "right") and "aboveleft" or "belowright"
|
||||||
|
|
||||||
-- Target is invalid or window does not exist in current tabpage: create new window
|
-- Target is invalid or window does not exist in current tabpage: create new window
|
||||||
if not vim.tbl_contains(win_ids, target_winid) then
|
if not vim.tbl_contains(win_ids, target_winid) then
|
||||||
vim.cmd(split_side .. " vsplit")
|
vim.cmd(new_window_side .. " vsplit")
|
||||||
target_winid = api.nvim_get_current_win()
|
target_winid = api.nvim_get_current_win()
|
||||||
lib.target_winid = target_winid
|
lib.target_winid = target_winid
|
||||||
|
|
||||||
-- No need to split, as we created a new window.
|
-- No need to split, as we created a new window.
|
||||||
do_split = false
|
create_new_window = false
|
||||||
elseif not vim.o.hidden then
|
elseif not vim.o.hidden then
|
||||||
-- If `hidden` is not enabled, check if buffer in target window is
|
-- If `hidden` is not enabled, check if buffer in target window is
|
||||||
-- modified, and create new split if it is.
|
-- modified, and create new split if it is.
|
||||||
local target_bufid = api.nvim_win_get_buf(target_winid)
|
local target_bufid = api.nvim_win_get_buf(target_winid)
|
||||||
if api.nvim_buf_get_option(target_bufid, "modified") then
|
if api.nvim_buf_get_option(target_bufid, "modified") then
|
||||||
do_split = true
|
mode = "vsplit"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local fname = vim.fn.fnameescape(filename)
|
local fname = vim.fn.fnameescape(filename)
|
||||||
|
|
||||||
local cmd
|
local cmd
|
||||||
if do_split or #api.nvim_list_wins() == 1 then
|
if create_new_window then
|
||||||
local split_cmd = (mode ~= "split") and "vsplit" or "split"
|
cmd = string.format("%s vsplit %s", new_window_side, fname)
|
||||||
cmd = string.format("%s %s %s", split_side, split_cmd, fname)
|
elseif mode:match "split$" then
|
||||||
|
cmd = string.format("%s %s", mode, fname)
|
||||||
else
|
else
|
||||||
cmd = string.format("edit %s", fname)
|
cmd = string.format("edit %s", fname)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user