Skip to content

Commit

Permalink
feat(mappings): show leaf node in preview window
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brandon1024 committed Jan 10, 2025
1 parent 56f7c0d commit 04d0158
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
24 changes: 24 additions & 0 deletions autoload/fern/scheme/file/mapping.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ function! fern#scheme#file#mapping#init(disable_default_mappings) abort
nnoremap <buffer><silent> <Plug>(fern-action-trash=) :<C-u>call <SID>call_without_guard('trash')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-remove) :<C-u>call <SID>call('remove')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-remove=) :<C-u>call <SID>call_without_guard('remove')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-preview) :<C-u>call <SID>call('preview', '')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-preview:jump) :<C-u>call <SID>call('preview', 'jump')<CR>
if !a:disable_default_mappings
nmap <buffer><nowait> N <Plug>(fern-action-new-file)
Expand Down Expand Up @@ -205,6 +207,28 @@ function! s:map_remove(helper) abort
\.then({ -> a:helper.sync.echo(printf('%d items are removed', len(ps))) })
endfunction

function! s:map_preview(helper, mode) abort
let node = a:helper.sync.get_cursor_node()
if node is# v:null
return s:Promise.reject('cursor node is not visible')
endif
if node.status isnot# a:helper.STATUS_NONE
return s:Promise.reject('cannot preview a directory')
endif

try
execute "noautocmd bo pedit " .. node._path

if a:mode ==# 'jump'
wincmd P
endif

return s:Promise.resolve()
catch
return s:Promise.reject(v:exception)
endtry
endfunction

function! s:new_file(helper, name) abort
let node = a:helper.sync.get_cursor_node()
let node = node.status isnot# a:helper.STATUS_EXPANDED ? node.__owner : node
Expand Down
11 changes: 9 additions & 2 deletions doc/fern.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ GLOBAL *fern-mapping-global*
\ <Plug>(fern-action-open:edit)
\ <Plug>(fern-action-open:edit-or-tabedit)
<

*<Plug>(fern-action-open)*
An alias to "open:edit" action. Users can overwrite this mapping to
change the default behavior of "open" action like:
Expand All @@ -1045,6 +1046,7 @@ GLOBAL *fern-mapping-global*
\ <Plug>(fern-action-open)
\ <Plug>(fern-action-open:select)
<

*<Plug>(fern-action-diff:select)*
*<Plug>(fern-action-diff:select:vert)*
Open a first marked node through "window selector"
Expand Down Expand Up @@ -1252,7 +1254,7 @@ The following mappings/actions are only available on file:// scheme.
nmap <buffer>
\ <Plug>(my-trash)
\ <Plug>(fern-action-trash=)y<CR>
<
*<Plug>(fern-action-remove)*
*<Plug>(fern-action-remove=)*
Open a prompt to ask if fern can DELETE the cursor node or marked
Expand All @@ -1265,7 +1267,7 @@ The following mappings/actions are only available on file:// scheme.
nmap <buffer>
\ <Plug>(my-trash)
\ <Plug>(fern-action-trash=)y<CR>
<
*<Plug>(fern-action-cd:root)*
*<Plug>(fern-action-lcd:root)*
*<Plug>(fern-action-tcd:root)*
Expand Down Expand Up @@ -1372,6 +1374,11 @@ The following mappings/actions are only available on file:// scheme.
Yank the node path. In FILE scheme, |<Plug>(fern-action-yank)| is
aliased to this mapping.

*<Plug>(fern-action-preview)*
*<Plug>(fern-action-preview:jump)*
Show the cursor node in the |preview-window|, optionally moving
the cursor to that window.

-----------------------------------------------------------------------------
DICT *fern-mapping-dict*

Expand Down

0 comments on commit 04d0158

Please sign in to comment.