summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2016-04-28 01:25:24 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2016-04-28 01:25:24 +0900
commit0231617857f812abfae5f68e2b8c7e9ce7053d59 (patch)
treed405c3b4004bc4588f282791b5c9aba8ee61bb9d /plugin
parent7f64fba80fd4a888adb9b279672ede7291525d5a (diff)
[neovim] Fix issues with `enew` and `tabnew` layouts
Related: #559
Diffstat (limited to 'plugin')
-rw-r--r--plugin/fzf.vim45
1 files changed, 23 insertions, 22 deletions
diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index 526f245e..d6a79f35 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! \<c-^>"
+ 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! \<c-^>"
- " 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