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

feat(git): quit git log win when it is last win

This commit is contained in:
Eric Wong 2024-02-25 21:25:02 +08:00
parent 89ddeb2497
commit 4c6a80d9a5
3 changed files with 36 additions and 3 deletions

View File

@ -1,5 +1,6 @@
let s:JOB = SpaceVim#api#import('job')
let s:BUFFER = SpaceVim#api#import('vim#buffer')
let s:WIN = SpaceVim#api#import('vim#window')
let s:NOTI = SpaceVim#api#import('notify')
let g:git_log_pretty = 'tformat:%Cred%h%Creset - %s %Cgreen(%an %ad)%Creset'
@ -109,11 +110,26 @@ function! s:openShowCommitBuffer() abort
return bufnr('%')
endfunction
function! s:is_last_win() abort
let num = winnr('$')
for i in range(1,num)
if s:WIN.is_float(win_getid(i))
let num = num - 1
endif
endfor
if num == 1
return 1
endif
endfunction
function! s:close_log_win() abort
call s:closeShowCommitWindow()
" @todo check if it is last win in current tab
"
" if it is the last win in current tab, use `:quit` instead
if tabpagenr('$') > 1 && s:is_last_win()
quit
return
endif
try
bp
catch /^Vim\%((\a\+)\)\=:E85/

View File

@ -4,6 +4,7 @@ local job = require('spacevim.api.job')
local nt = require('spacevim.api.notify')
local log = require('git.log')
local str = require('spacevim.api.data.string')
local win = require('spacevim.api.vim.window')
local git_log_pretty = 'tformat:%Cred%h%Creset - %s %Cgreen(%an %ad)%Creset'
local bufnr = -1
@ -17,7 +18,22 @@ 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
vim.cmd('quit')
return
end
local ok = pcall(function()
vim.cmd('bp')
end)

View File

@ -46,6 +46,7 @@ The roadmap defines the project direction and priorities.
- [x] register project function with description
- [x] update todo list when switch project
- [x] make `one` coloscheme support treesitter
- [x] quit git log win when it is last win
## Completed