From 0231617857f812abfae5f68e2b8c7e9ce7053d59 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Thu, 28 Apr 2016 01:25:24 +0900 Subject: [PATCH] [neovim] Fix issues with `enew` and `tabnew` layouts Related: #559 --- plugin/fzf.vim | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 526f245..d6a79f3 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -298,7 +298,7 @@ function! s:split(dict) \ 'down': ['botright', 'resize', &lines], \ 'left': ['vertical topleft', 'vertical resize', &columns], \ 'right': ['vertical botright', 'vertical resize', &columns] } - let s:ppos = s:getpos() + let ppos = s:getpos() try for [dir, triple] in items(directions) let val = get(a:dict, dir, '') @@ -311,7 +311,7 @@ function! s:split(dict) endif execute cmd sz.'new' execute resz sz - return {} + return [ppos, {}] endif endfor if s:present(a:dict, 'window') @@ -319,36 +319,44 @@ function! s:split(dict) else execute (tabpagenr()-1).'tabnew' endif - return { '&l:wfw': &l:wfw, '&l:wfh': &l:wfh } + return [ppos, { '&l:wfw': &l:wfw, '&l:wfh': &l:wfh }] finally setlocal winfixwidth winfixheight endtry endfunction function! s:execute_term(dict, command, temps) abort - let winopts = s:split(a:dict) - - let fzf = { 'buf': bufnr('%'), 'dict': a:dict, 'temps': a:temps, 'name': 'FZF', 'winopts': winopts } - let s:command = a:command + let [ppos, winopts] = s:split(a:dict) + let fzf = { 'buf': bufnr('%'), 'ppos': ppos, 'dict': a:dict, 'temps': a:temps, + \ 'name': 'FZF', 'winopts': winopts, 'command': a:command } + function! fzf.switch_back(inplace) + if a:inplace && bufnr('') == self.buf + " FIXME: Can't re-enter normal mode from terminal mode + " execute "normal! \" + b # + " No other listed buffer + if bufnr('') == self.buf + enew + endif + endif + endfunction function! fzf.on_exit(id, code) - let pos = s:getpos() - let inplace = pos == s:ppos " {'window': 'enew'} - if inplace + if s:getpos() == self.ppos " {'window': 'enew'} for [opt, val] in items(self.winopts) execute 'let' opt '=' val endfor + call self.switch_back(1) else if bufnr('') == self.buf " We use close instead of bd! since Vim does not close the split when " there's no other listed buffer (nvim +'set nobuflisted') close endif - if pos.tab == s:ppos.tab - wincmd p - endif + execute 'tabnext' self.ppos.tab + execute self.ppos.win.'wincmd w' endif - if !s:exit_handler(a:code, s:command, 1) + if !s:exit_handler(a:code, self.command, 1) return endif @@ -356,14 +364,7 @@ function! s:execute_term(dict, command, temps) abort let ret = [] try let ret = s:callback(self.dict, self.temps) - - if inplace && bufnr('') == self.buf - execute "normal! \" - " No other listed buffer - if bufnr('') == self.buf - bd! - endif - endif + call self.switch_back(s:getpos() == self.ppos) finally call s:popd(self.dict, ret) endtry