Skip to content

Commit d677908

Browse files
committed
feat(mappings): show leaf node in preview window
This revision introduces new plugin mappings for showing the current leaf node in a preview window, through the 'preview' and 'preview:jump' actions available for the 'file://' scheme. Documentation has been updated accordingly.
1 parent 56f7c0d commit d677908

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

autoload/fern/scheme/file/mapping.vim

+24
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ function! fern#scheme#file#mapping#init(disable_default_mappings) abort
1313
nnoremap <buffer><silent> <Plug>(fern-action-trash=) :<C-u>call <SID>call_without_guard('trash')<CR>
1414
nnoremap <buffer><silent> <Plug>(fern-action-remove) :<C-u>call <SID>call('remove')<CR>
1515
nnoremap <buffer><silent> <Plug>(fern-action-remove=) :<C-u>call <SID>call_without_guard('remove')<CR>
16+
nnoremap <buffer><silent> <Plug>(fern-action-preview) :<C-u>call <SID>call('preview', '')<CR>
17+
nnoremap <buffer><silent> <Plug>(fern-action-preview:jump) :<C-u>call <SID>call('preview', 'jump')<CR>
1618
1719
if !a:disable_default_mappings
1820
nmap <buffer><nowait> N <Plug>(fern-action-new-file)
@@ -205,6 +207,28 @@ function! s:map_remove(helper) abort
205207
\.then({ -> a:helper.sync.echo(printf('%d items are removed', len(ps))) })
206208
endfunction
207209

210+
function! s:map_preview(helper, mode) abort
211+
let node = a:helper.sync.get_cursor_node()
212+
if node is# v:null
213+
return s:Promise.reject('cursor node is not visible')
214+
endif
215+
if node.status isnot# a:helper.STATUS_NONE
216+
return s:Promise.reject('cannot preview a directory')
217+
endif
218+
219+
try
220+
execute "noautocmd bo pedit " .. node._path
221+
222+
if a:mode ==# 'jump'
223+
wincmd P
224+
endif
225+
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

+9-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,11 @@ 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)*
1378+
*<Plug>(fern-action-preview:jump)*
1379+
Show the cursor node in the |preview-window|, optionally moving
1380+
the cursor to that window.
1381+
13751382
-----------------------------------------------------------------------------
13761383
DICT *fern-mapping-dict*
13771384

0 commit comments

Comments
 (0)