From d7a9ec1b7522e7f478f6b7101090a9a091d302c5 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 3 Jun 2017 15:07:09 +0800 Subject: [PATCH] Undo general quited window --- autoload/SpaceVim/autocmds.vim | 1 + autoload/SpaceVim/plugins/windowsmanager.vim | 43 ++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/autoload/SpaceVim/autocmds.vim b/autoload/SpaceVim/autocmds.vim index 68da1a62a..042bc67f2 100644 --- a/autoload/SpaceVim/autocmds.vim +++ b/autoload/SpaceVim/autocmds.vim @@ -17,6 +17,7 @@ function! SpaceVim#autocmds#init() abort \ q | endif autocmd FileType jsp call JspFileTypeInit() autocmd QuitPre * call SpaceVim#plugins#windowsmanager#UpdateRestoreWinInfo() + autocmd WinEnter * call SpaceVim#plugins#windowsmanager#MarkBaseWin() autocmd FileType html,css,jsp EmmetInstall autocmd BufRead,BufNewFile *.pp setfiletype puppet if g:spacevim_enable_cursorline == 1 diff --git a/autoload/SpaceVim/plugins/windowsmanager.vim b/autoload/SpaceVim/plugins/windowsmanager.vim index bd81cce99..8b517719f 100644 --- a/autoload/SpaceVim/plugins/windowsmanager.vim +++ b/autoload/SpaceVim/plugins/windowsmanager.vim @@ -2,12 +2,17 @@ let s:TAB = SpaceVim#api#import('vim#tab') let s:restore_windows_stack = [] +let s:unmarked = 0 + function! s:get_window_restore_data() abort let win_data = { - \ 'bufid': bufnr('%'), + \ 'bufname': fnamemodify(bufname('%'), ':p'), \ 'tabpagenr': tabpagenr(), \ 'view': winsaveview(), + \ 'newtab':0, + \ 'oldwinid' : -1, + \ 'same_w' : 0, \ } return win_data endfunction @@ -16,10 +21,16 @@ function! SpaceVim#plugins#windowsmanager#UpdateRestoreWinInfo() abort if !&buflisted return endif + let s:unmarked = 1 let win_data = s:get_window_restore_data() if len(tabpagebuflist()) == 1 - let win_data.neighbour_buffer = '' + let win_data.newtab = 1 let win_data.open_command = (tabpagenr() - 1).'tabnew' + else + if winwidth(winnr()) == &columns + let win_data.same_w = 1 + endif + let win_data.oldwinid = winnr() endif call add(s:restore_windows_stack, win_data) endfunction @@ -29,7 +40,31 @@ function! SpaceVim#plugins#windowsmanager#UndoQuitWin() return endif let win_data = remove(s:restore_windows_stack, -1) - if win_data.neighbour_buffer != '' + if win_data.newtab + exe win_data.open_command . ' ' . win_data.bufname + else + exe win_data.open_command + endif +endfunction + +function! SpaceVim#plugins#windowsmanager#MarkBaseWin() + if s:unmarked + let win_data = s:restore_windows_stack[-1] + if win_data.same_w + " split + if win_data.oldwinid == winnr() + let win_data.open_command = 'topleft split ' . win_data.bufname + else + let win_data.open_command = 'rightbelow split ' . win_data.bufname + endif + else + " vsplit + if win_data.oldwinid == winnr() + let win_data.open_command = 'topleft vsplit ' . win_data.bufname + else + let win_data.open_command = 'rightbelow vsplit ' . win_data.bufname + endif + endif + let s:unmarked = 0 endif - exe win_data.open_command . ' | b ' win_data.bufid endfunction