Skip to content
Myr

[vim] Dynamic height specification for 'up' and 'down' options

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Values for 'up' and 'down' can be written with ~ prefix. Only applies when the source is a Vim list. e.g. { 'source': range(10), 'down': '~40%' }

authored by Junegunn Choi · committed by Junegunn Choi · parent 1de4cc3 · Browse files · 1 file+24 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+24 added−5 removed

  • other:+24 added−5 removed

1 file+24 added−5 removed

modified:plugin/fzf.vim+24 added-5 removed
162 unmodified lines
163function! s:fzf_tmux(dict)164 let size = ''165 for o in ['up', 'down', 'left', 'right']166 if s:present(a:dict, o)167 let size = '-'.o[0].(a:dict[o] == 1 ? '' : a:dict[o])167 let spec = a:dict[o]168 if (o == 'up' || o == 'down') && spec[0] == '~'169 let size = '-'.o[0].s:calc_size(&lines, spec[1:], a:dict)170 else171 " Legacy boolean option172 let size = '-'.o[0].(spec == 1 ? '' : spec)173 endif174 break175 endif176 endfor177 return printf('LINES=%d COLUMNS=%d %s %s %s --',
71 unmodified lines
249 redraw!250 return s:callback(a:dict, a:temps)251endfunction252247function! s:calc_size(max, val)253function! s:calc_size(max, val, dict)254 if a:val =~ '%$'249 return a:max * str2nr(a:val[:-2]) / 100255 let size = a:max * str2nr(a:val[:-2]) / 100256 else251 return min([a:max, a:val])257 let size = min([a:max, str2nr(a:val)])258 endif259260 let srcsz = -1261 if type(get(a:dict, 'source', 0)) == type([])262 let srcsz = len(a:dict.source)263 endif264265 let opts = get(a:dict, 'options', '').$FZF_DEFAULT_OPTS266 let margin = stridx(opts, '--inline-info') > stridx(opts, '--no-inline-info') ? 1 : 2267 return srcsz >= 0 ? min([srcsz + margin, size]) : size268endfunction269270function! s:getpos()271 return {'tab': tabpagenr(), 'win': winnr(), 'cnt': winnr('$')}
10 unmodified lines
282 for [dir, triple] in items(directions)283 let val = get(a:dict, dir, '')284 if !empty(val)285 let [cmd, resz, max] = triple286 if (dir == 'up' || dir == 'down') && val[0] == '~'287 let sz = s:calc_size(max, val[1:], a:dict)288 else271 let sz = s:calc_size(max, val)289 let sz = s:calc_size(max, val, {})290 endif291 execute cmd sz.'new'292 execute resz sz293 return294 endif
124 unmodified lines