1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 11:20:06 +08:00

fix(git): fix close_diff_win in diff.lua

winnr('$') includes floating windows in neovim
This commit is contained in:
Eric Wong 2024-03-02 21:28:27 +08:00
parent f56ae9c4db
commit a3944d67fb
3 changed files with 25 additions and 21 deletions

View File

@ -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

View File

@ -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

View File

@ -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