diff --git a/bundle/git.vim/lua/git/command/diff.lua b/bundle/git.vim/lua/git/command/diff.lua index 11a7c5872..87ebff93c 100644 --- a/bundle/git.vim/lua/git/command/diff.lua +++ b/bundle/git.vim/lua/git/command/diff.lua @@ -3,6 +3,7 @@ local M = {} local job = require('spacevim.api.job') local nt = require('spacevim.api.notify') local log = require('git.log') +local win = require('spacevim.api.vim.window') local diff_lines = {} local jobid = -1 @@ -30,10 +31,10 @@ local function on_stderr(id, data) end local function close_diff_win() - if vim.fn.winnr('$') > 1 then - vim.cmd('close') - else + if win.is_last_win() then vim.cmd('bd!') + else + vim.cmd('close') end end diff --git a/bundle/git.vim/lua/git/command/log.lua b/bundle/git.vim/lua/git/command/log.lua index 75bc2b459..735fb2dec 100644 --- a/bundle/git.vim/lua/git/command/log.lua +++ b/bundle/git.vim/lua/git/command/log.lua @@ -18,19 +18,8 @@ local function close_commit_win() end end -local function is_last_win() - local win_list = vim.api.nvim_tabpage_list_wins(0) - local num = #win_list - for _, v in ipairs(win_list) do - if win.is_float(v) then - num = num - 1 - end - end - return num == 1 -end - local function close_log_win() - if vim.fn.tabpagenr('$') > 1 and is_last_win() then + if vim.fn.tabpagenr('$') > 1 and win.is_last_win() then vim.cmd('quit') return end diff --git a/lua/spacevim/api/vim/window.lua b/lua/spacevim/api/vim/window.lua index e0acc3293..94277d738 100644 --- a/lua/spacevim/api/vim/window.lua +++ b/lua/spacevim/api/vim/window.lua @@ -1,6 +1,6 @@ -local window = {} +local M = {} -function window.get_cursor(window_id) +function M.get_cursor(window_id) local winindex = vim.eval("win_id2win(" .. window_id .. ")") local w = vim.window(winindex) if w == nil then @@ -10,18 +10,32 @@ function window.get_cursor(window_id) end end -function window.set_cursor(window_id, pos) +function M.set_cursor(window_id, pos) local winindex = vim.eval("win_id2win(" .. window_id .. ")") local w = vim.window(winindex) w.line = pos[0] w.col = pos[1] end -function window.close(window_id) +function M.close(window_id) end -function window.is_float(winid) + +-- neovim winnr('$') includes floating windows +function M.is_last_win() + local win_list = vim.api.nvim_tabpage_list_wins(0) + local num = #win_list + for _, v in ipairs(win_list) do + if M.is_float(v) then + num = num - 1 + end + end + return num == 1 + +end + +function M.is_float(winid) if winid > 0 then local ok, c = pcall(vim.api.nvim_win_get_config, winid) if ok and c.col ~= nil then @@ -35,6 +49,6 @@ function window.is_float(winid) end -return window +return M