1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 17:50:04 +08:00

Fix: smart quit should skip floating windows and popup (#3640)

@bug vim winnr('$') do not include popup
 ref: https://github.com/vim/vim/issues/6474
This commit is contained in:
Wang Shidong 2020-07-18 10:43:52 +08:00 committed by GitHub
parent c937c0e2fd
commit 823d288b35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 10 deletions

View File

@ -29,7 +29,7 @@ if exists('*nvim_win_get_cursor')
endfunction
elseif g:_spacevim_if_lua
function! s:self.get_cursor(winid) abort
lua require("spacevim.api.vim.window").get_cursor(vim.eval("a:winid"))
lua require("spacevim.api.vim.window").get_cursor(vim.eval("a:winid"))
endfunction
else
function! s:self.get_cursor(winid) abort
@ -42,23 +42,47 @@ if exists('*nvim_win_set_cursor')
return nvim_win_set_cursor(a:winid, a:pos)
endfunction
elseif exists('*win_execute')
function! s:self.set_cursor(win, pos) abort
" @fixme use g` to move to cursor line
" this seem to be a bug of vim
" https://github.com/vim/vim/issues/5022
call win_execute(a:win, ':call cursor(' . a:pos[0] . ', ' . a:pos[1] . ')')
" call win_execute(a:win, ':' . a:pos[0])
call win_execute(a:win, ':normal! g"')
endfunction
function! s:self.set_cursor(win, pos) abort
" @fixme use g` to move to cursor line
" this seem to be a bug of vim
" https://github.com/vim/vim/issues/5022
call win_execute(a:win, ':call cursor(' . a:pos[0] . ', ' . a:pos[1] . ')')
" call win_execute(a:win, ':' . a:pos[0])
call win_execute(a:win, ':normal! g"')
endfunction
elseif g:_spacevim_if_lua
function! s:self.set_cursor(winid, pos) abort
lua require("spacevim.api.vim.window").set_cursor(vim.eval("a:winid"), vim.eval("a:pos"))
lua require("spacevim.api.vim.window").set_cursor(vim.eval("a:winid"), vim.eval("a:pos"))
endfunction
else
function! s:self.set_cursor(winid, pos) abort
endfunction
endif
if has('nvim')
function! s:self.is_float(winnr) abort
let id = win_getid(a:winnr)
if id > 0
return has_key(nvim_win_get_config(id), 'col')
else
return 0
endif
endfunction
else
function! s:self.is_float(winnr) abort
let id = win_getid(a:winnr)
if id > 0
try
return has_key(popup_getoptions(id), 'col')
catch /^Vim\%((\a\+)\)\=:E993/
return 0
endtry
else
return 0
endif
endfunction
endif
function! SpaceVim#api#vim#window#get() abort
return deepcopy(s:self)

View File

@ -9,6 +9,7 @@
scriptencoding utf-8
let s:BUFFER = SpaceVim#api#import('vim#buffer')
let s:WIN = SpaceVim#api#import('vim#window')
let g:unite_source_menu_menus =
@ -289,6 +290,8 @@ endfunction
fu! SpaceVim#mapping#SmartClose() abort
let ignorewin = get(g:,'spacevim_smartcloseignorewin',[])
let ignoreft = get(g:, 'spacevim_smartcloseignoreft',[])
" @bug vim winnr('$') do not include popup
" ref: https://github.com/vim/vim/issues/6474
let win_count = winnr('$')
let num = win_count
for i in range(1,win_count)
@ -298,6 +301,8 @@ fu! SpaceVim#mapping#SmartClose() abort
let num = num - 1
elseif getwinvar(i, '&previewwindow') == 1 && winnr() !=# i
let num = num - 1
elseif s:WIN.is_float(i)
let num = num - 1
endif
endfor
if num == 1