Skip to content

Commit f1f4b88

Browse files
committed
Improve 'zoom' related actions
- The 'zoom' action ask users for the desired ratio or use v:count - The 'zoom:reset' action is used to get the original width back Now user can use "7z" to get 70% width drawer and "Z" to get back. This is mainly for helping a usage explained in a feature request #309 #309
1 parent 13c2dbe commit f1f4b88

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

autoload/fern/mapping/drawer.vim

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
function! fern#mapping#drawer#init(disable_default_mappings) abort
2-
nnoremap <buffer><silent> <Plug>(fern-action-zoom:half) :<C-u>call <SID>call('zoom', 0.4)<CR>
3-
nnoremap <buffer><silent> <Plug>(fern-action-zoom:full) :<C-u>call <SID>call('zoom', 0.9)<CR>
4-
5-
nmap <buffer> <Plug>(fern-action-zoom) <Plug>(fern-action-zoom:half)
2+
nnoremap <buffer><silent> <Plug>(fern-action-zoom) :<C-u>call <SID>call('zoom')<CR>
3+
nnoremap <buffer><silent> <Plug>(fern-action-zoom:reset) :<C-u>call <SID>call('zoom_reset')<CR>
4+
nmap <buffer><silent> <Plug>(fern-action-zoom:half) 4<Plug>(fern-action-zoom)
5+
nmap <buffer><silent> <Plug>(fern-action-zoom:full) 9<Plug>(fern-action-zoom)
66
77
if !a:disable_default_mappings
88
nmap <buffer><nowait> z <Plug>(fern-action-zoom)
9+
nmap <buffer><nowait> Z <Plug>(fern-action-zoom:reset)
910
endif
1011
endfunction
1112

@@ -16,9 +17,35 @@ function! s:call(name, ...) abort
1617
\)
1718
endfunction
1819

19-
function! s:map_zoom(helper, alpha) abort
20-
if fern#internal#drawer#is_drawer()
21-
let width = &columns * a:alpha
22-
execute printf('%d wincmd |', float2nr(width))
20+
function! s:map_zoom(helper) abort
21+
if !fern#internal#drawer#is_drawer()
22+
call fern#warn('zoom is available only on drawer')
23+
return
24+
endif
25+
let alpha = v:count
26+
if alpha <= 0 || alpha > 10
27+
let alpha = s:input_alpha('Width ratio [1-10]: ')
2328
endif
29+
let alpha = str2float(alpha)
30+
let width = &columns * (alpha / 10)
31+
execute 'vertical resize' float2nr(width)
32+
endfunction
33+
34+
function! s:map_zoom_reset(helper) abort
35+
if !fern#internal#drawer#is_drawer()
36+
call fern#warn('zoom:resize is available only on drawer')
37+
return
38+
endif
39+
call fern#internal#drawer#resize()
40+
endfunction
41+
42+
function! s:input_alpha(prompt) abort
43+
while v:true
44+
let result = input(a:prompt)
45+
if result =~# '^\%(10\|[1-9]\)$'
46+
redraw | echo ''
47+
return result
48+
endif
49+
redraw | echo 'Please input a digit from 1 to 10'
50+
endwhile
2451
endfunction

doc/fern.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -781,16 +781,22 @@ See |fern-action| for more detail.
781781
-----------------------------------------------------------------------------
782782
GLOBAL *fern-mapping-global*
783783

784-
*<Plug>(fern-action-zoom:half)*
785-
Zoom width of the drawer style fern to half of the global width.
786-
The original window width will be restored once user leave the window.
784+
*<Plug>(fern-action-zoom)*
785+
Zoom width of the drawer style fern to the ratio of the global width.
786+
It prompt users to ask a desired ratio of the width if no |v:count| is
787+
given. Users can use 1 to 10 for the ratio.
787788
It only works on a drawer style fern window.
788789

789-
*<Plug>(fern-action-zoom:full)*
790-
Zoom width of the drawer style fern to full of the global width.
791-
The original window width will be restored once user leave the window.
790+
*<Plug>(fern-action-zoom:reset)*
791+
Reset the width of the drawer style fern to its original width.
792792
It only works on a drawer style fern window.
793793

794+
*<Plug>(fern-action-zoom:half)*
795+
This is an alias of "4<Plug>(fern-action-zoom)"
796+
797+
*<Plug>(fern-action-zoom:full)*
798+
This is an alias of "9<Plug>(fern-action-zoom)"
799+
794800
*<Plug>(fern-action-hidden:set)*
795801
Show hidden nodes. For example hidden nodes in file:// scheme is a
796802
file or directory starts from '.' character.

0 commit comments

Comments
 (0)