mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 13:10:04 +08:00
feat(git): quit git log win when it is last win
This commit is contained in:
parent
89ddeb2497
commit
4c6a80d9a5
@ -1,5 +1,6 @@
|
|||||||
let s:JOB = SpaceVim#api#import('job')
|
let s:JOB = SpaceVim#api#import('job')
|
||||||
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
let s:BUFFER = SpaceVim#api#import('vim#buffer')
|
||||||
|
let s:WIN = SpaceVim#api#import('vim#window')
|
||||||
let s:NOTI = SpaceVim#api#import('notify')
|
let s:NOTI = SpaceVim#api#import('notify')
|
||||||
|
|
||||||
let g:git_log_pretty = 'tformat:%Cred%h%Creset - %s %Cgreen(%an %ad)%Creset'
|
let g:git_log_pretty = 'tformat:%Cred%h%Creset - %s %Cgreen(%an %ad)%Creset'
|
||||||
@ -109,11 +110,26 @@ function! s:openShowCommitBuffer() abort
|
|||||||
return bufnr('%')
|
return bufnr('%')
|
||||||
endfunction
|
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
|
function! s:close_log_win() abort
|
||||||
call s:closeShowCommitWindow()
|
call s:closeShowCommitWindow()
|
||||||
" @todo check if it is last win in current tab
|
if tabpagenr('$') > 1 && s:is_last_win()
|
||||||
"
|
quit
|
||||||
" if it is the last win in current tab, use `:quit` instead
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
try
|
try
|
||||||
bp
|
bp
|
||||||
catch /^Vim\%((\a\+)\)\=:E85/
|
catch /^Vim\%((\a\+)\)\=:E85/
|
||||||
|
@ -4,6 +4,7 @@ local job = require('spacevim.api.job')
|
|||||||
local nt = require('spacevim.api.notify')
|
local nt = require('spacevim.api.notify')
|
||||||
local log = require('git.log')
|
local log = require('git.log')
|
||||||
local str = require('spacevim.api.data.string')
|
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 git_log_pretty = 'tformat:%Cred%h%Creset - %s %Cgreen(%an %ad)%Creset'
|
||||||
local bufnr = -1
|
local bufnr = -1
|
||||||
@ -17,7 +18,22 @@ local function close_commit_win()
|
|||||||
end
|
end
|
||||||
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()
|
local function close_log_win()
|
||||||
|
if vim.fn.tabpagenr('$') > 1 and is_last_win() then
|
||||||
|
vim.cmd('quit')
|
||||||
|
return
|
||||||
|
end
|
||||||
local ok = pcall(function()
|
local ok = pcall(function()
|
||||||
vim.cmd('bp')
|
vim.cmd('bp')
|
||||||
end)
|
end)
|
||||||
|
@ -46,6 +46,7 @@ The roadmap defines the project direction and priorities.
|
|||||||
- [x] register project function with description
|
- [x] register project function with description
|
||||||
- [x] update todo list when switch project
|
- [x] update todo list when switch project
|
||||||
- [x] make `one` coloscheme support treesitter
|
- [x] make `one` coloscheme support treesitter
|
||||||
|
- [x] quit git log win when it is last win
|
||||||
|
|
||||||
|
|
||||||
## Completed
|
## Completed
|
||||||
|
Loading…
Reference in New Issue
Block a user