Skip to content

Commit cb5be74

Browse files
authored
feat(mappings): show leaf node in preview window (#518)
This revision introduces new plugin mappings for showing the current leaf node in a preview window, through the 'preview' and 'preview:*' actions available for the 'file://' scheme. Documentation has been updated accordingly.
1 parent 0912da5 commit cb5be74

File tree

2 files changed

+53
-14
lines changed

2 files changed

+53
-14
lines changed

autoload/fern/scheme/file/mapping.vim

+36-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
let s:Promise = vital#fern#import('Async.Promise')
22

33
function! fern#scheme#file#mapping#init(disable_default_mappings) abort
4-
nnoremap <buffer><silent> <Plug>(fern-action-new-path) :<C-u>call <SID>call('new_path')<CR>
5-
nnoremap <buffer><silent> <Plug>(fern-action-new-file) :<C-u>call <SID>call('new_file')<CR>
6-
nnoremap <buffer><silent> <Plug>(fern-action-new-dir) :<C-u>call <SID>call('new_dir')<CR>
7-
nnoremap <buffer><silent> <Plug>(fern-action-new-path=) :<C-u>call <SID>call_without_guard('new_path')<CR>
8-
nnoremap <buffer><silent> <Plug>(fern-action-new-file=) :<C-u>call <SID>call_without_guard('new_file')<CR>
9-
nnoremap <buffer><silent> <Plug>(fern-action-new-dir=) :<C-u>call <SID>call_without_guard('new_dir')<CR>
10-
nnoremap <buffer><silent> <Plug>(fern-action-copy) :<C-u>call <SID>call('copy')<CR>
11-
nnoremap <buffer><silent> <Plug>(fern-action-move) :<C-u>call <SID>call('move')<CR>
12-
nnoremap <buffer><silent> <Plug>(fern-action-trash) :<C-u>call <SID>call('trash')<CR>
13-
nnoremap <buffer><silent> <Plug>(fern-action-trash=) :<C-u>call <SID>call_without_guard('trash')<CR>
14-
nnoremap <buffer><silent> <Plug>(fern-action-remove) :<C-u>call <SID>call('remove')<CR>
15-
nnoremap <buffer><silent> <Plug>(fern-action-remove=) :<C-u>call <SID>call_without_guard('remove')<CR>
4+
nnoremap <buffer><silent> <Plug>(fern-action-new-path) :<C-u>call <SID>call('new_path')<CR>
5+
nnoremap <buffer><silent> <Plug>(fern-action-new-file) :<C-u>call <SID>call('new_file')<CR>
6+
nnoremap <buffer><silent> <Plug>(fern-action-new-dir) :<C-u>call <SID>call('new_dir')<CR>
7+
nnoremap <buffer><silent> <Plug>(fern-action-new-path=) :<C-u>call <SID>call_without_guard('new_path')<CR>
8+
nnoremap <buffer><silent> <Plug>(fern-action-new-file=) :<C-u>call <SID>call_without_guard('new_file')<CR>
9+
nnoremap <buffer><silent> <Plug>(fern-action-new-dir=) :<C-u>call <SID>call_without_guard('new_dir')<CR>
10+
nnoremap <buffer><silent> <Plug>(fern-action-copy) :<C-u>call <SID>call('copy')<CR>
11+
nnoremap <buffer><silent> <Plug>(fern-action-move) :<C-u>call <SID>call('move')<CR>
12+
nnoremap <buffer><silent> <Plug>(fern-action-trash) :<C-u>call <SID>call('trash')<CR>
13+
nnoremap <buffer><silent> <Plug>(fern-action-trash=) :<C-u>call <SID>call_without_guard('trash')<CR>
14+
nnoremap <buffer><silent> <Plug>(fern-action-remove) :<C-u>call <SID>call('remove')<CR>
15+
nnoremap <buffer><silent> <Plug>(fern-action-remove=) :<C-u>call <SID>call_without_guard('remove')<CR>
16+
nnoremap <buffer><silent> <Plug>(fern-action-preview:left) :<C-u>call <SID>call('preview', 'vertical topleft')<CR>
17+
nnoremap <buffer><silent> <Plug>(fern-action-preview:right) :<C-u>call <SID>call('preview', 'vertical botright')<CR>
18+
nnoremap <buffer><silent> <Plug>(fern-action-preview:top) :<C-u>call <SID>call('preview', 'topleft')<CR>
19+
nnoremap <buffer><silent> <Plug>(fern-action-preview:bottom) :<C-u>call <SID>call('preview', 'botright')<CR>
20+
21+
" Alias map
22+
nnoremap <buffer><silent> <Plug>(fern-action-preview) <Plug>(fern-action-preview:bottom)
1623
1724
if !a:disable_default_mappings
1825
nmap <buffer><nowait> N <Plug>(fern-action-new-file)
@@ -205,6 +212,23 @@ function! s:map_remove(helper) abort
205212
\.then({ -> a:helper.sync.echo(printf('%d items are removed', len(ps))) })
206213
endfunction
207214

215+
function! s:map_preview(helper, prefix) abort
216+
let node = a:helper.sync.get_cursor_node()
217+
if node is# v:null
218+
return s:Promise.reject('cursor node is not visible')
219+
endif
220+
if node.status isnot# a:helper.STATUS_NONE
221+
return s:Promise.resolve()
222+
endif
223+
224+
try
225+
execute printf("noautocmd %s pedit %s", a:prefix, fnameescape(node._path))
226+
return s:Promise.resolve()
227+
catch
228+
return s:Promise.reject(v:exception)
229+
endtry
230+
endfunction
231+
208232
function! s:new_file(helper, name) abort
209233
let node = a:helper.sync.get_cursor_node()
210234
let node = node.status isnot# a:helper.STATUS_EXPANDED ? node.__owner : node

doc/fern.txt

+17-2
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,7 @@ GLOBAL *fern-mapping-global*
10371037
\ <Plug>(fern-action-open:edit)
10381038
\ <Plug>(fern-action-open:edit-or-tabedit)
10391039
<
1040+
10401041
*<Plug>(fern-action-open)*
10411042
An alias to "open:edit" action. Users can overwrite this mapping to
10421043
change the default behavior of "open" action like:
@@ -1045,6 +1046,7 @@ GLOBAL *fern-mapping-global*
10451046
\ <Plug>(fern-action-open)
10461047
\ <Plug>(fern-action-open:select)
10471048
<
1049+
10481050
*<Plug>(fern-action-diff:select)*
10491051
*<Plug>(fern-action-diff:select:vert)*
10501052
Open a first marked node through "window selector"
@@ -1252,7 +1254,7 @@ The following mappings/actions are only available on file:// scheme.
12521254
nmap <buffer>
12531255
\ <Plug>(my-trash)
12541256
\ <Plug>(fern-action-trash=)y<CR>
1255-
1257+
<
12561258
*<Plug>(fern-action-remove)*
12571259
*<Plug>(fern-action-remove=)*
12581260
Open a prompt to ask if fern can DELETE the cursor node or marked
@@ -1265,7 +1267,7 @@ The following mappings/actions are only available on file:// scheme.
12651267
nmap <buffer>
12661268
\ <Plug>(my-trash)
12671269
\ <Plug>(fern-action-trash=)y<CR>
1268-
1270+
<
12691271
*<Plug>(fern-action-cd:root)*
12701272
*<Plug>(fern-action-lcd:root)*
12711273
*<Plug>(fern-action-tcd:root)*
@@ -1372,6 +1374,19 @@ The following mappings/actions are only available on file:// scheme.
13721374
Yank the node path. In FILE scheme, |<Plug>(fern-action-yank)| is
13731375
aliased to this mapping.
13741376

1377+
*<Plug>(fern-action-preview:left)*
1378+
*<Plug>(fern-action-preview:right)*
1379+
*<Plug>(fern-action-preview:top)*
1380+
*<Plug>(fern-action-preview:bottom)*
1381+
*<Plug>(fern-action-preview)*
1382+
Show the cursor node in a |preview-window| in similar manners of global
1383+
"open" actions.
1384+
If you would like to jump to the preview window, you can register a
1385+
mapping like:
1386+
>
1387+
nnoremap P <Plug>(fern-action-preview)<C-w>p
1388+
<
1389+
13751390
-----------------------------------------------------------------------------
13761391
DICT *fern-mapping-dict*
13771392

0 commit comments

Comments
 (0)