Skip to content

Commit

Permalink
added option for popups to replace each other
Browse files Browse the repository at this point in the history
  • Loading branch information
zhamlin committed Oct 2, 2017
1 parent e2c4f90 commit 30cb74d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions doc/tiler.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ g:tiler#popup#windows *g:tiler#popup#windows*
1 will be moved last, putting it on top of all the other
popups. See EXAMPLES for a picture.

"replace" Number 0 or 1
Popup will be replaced by another popup when both
'replace' and 'position' are the same for both popups.

Default: {}

------------------------------------------------------------------------------
Expand Down
29 changes: 29 additions & 0 deletions plugin/tiler.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ endif

let s:popup_is_vertical = { 'left': 1, 'right': 1, 'top': 0, 'bottom': 0 }
let s:popup_directions = { 'right': 'L', 'left': 'H', 'top': 'K', 'bottom': 'J' }
let s:saved_popups = {}

let s:tile_layouts_master = { 'right': 'H', 'left': 'L', 'top': 'J', 'bottom': 'K' }
let s:tile_layouts_stack = { 'right': 'K', 'left': 'J', 'top': 'L', 'bottom': 'H' }
Expand All @@ -55,6 +56,11 @@ function! s:winmaxheight()
return l:height
endfunction

function! s:window_close(win)
execute printf('silent %d wincmd w', a:win)
close
endfunction

function! s:window_move(dir, ...)
let a:winnum = get(a:, 1, winnr())
execute printf('silent %d wincmd w', a:winnum)
Expand Down Expand Up @@ -82,6 +88,18 @@ function! s:sort_popups(a, b)
return get(a:a.vars, 'order', 0) < get(a:b.vars, 'order', 0)
endfunction

function! s:get_saved_popups()
let l:current_tab = tabpagenr()
if empty(get(s:saved_popups, l:current_tab))
let s:saved_popups[l:current_tab] = []
endif
return s:saved_popups[l:current_tab]
endfunction

function! s:set_saved_popups(popups)
let s:saved_popups[tabpagenr()] = a:popups
endfunction

function! s:find_popups()
let l:popups = []

Expand Down Expand Up @@ -267,6 +285,17 @@ function! tiler#reorder()
let l:currwin = win_getid()
call tiler#stack_windows()

let l:new_popups = filter(copy(l:popups), 'index(s:get_saved_popups(), v:val) < 0 && get(v:val.vars, "replace", 0)')
for popup in l:new_popups
let l:popups_to_close = filter(copy(l:popups), 'v:val != popup && get(v:val.vars, "replace", 0) && popup.vars.position ==# v:val.vars.position')
for win in map(l:popups_to_close, 'win_id2win(v:val.id)')
call s:window_close(win)
endfor
endfor

let l:popups = s:find_popups()
call s:set_saved_popups(l:popups)

let l:current_layout = s:get_current_layout()
" move popup windows to bottom of stack and remove from list of current windows
for popup in l:popups
Expand Down

0 comments on commit 30cb74d

Please sign in to comment.