Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mappings): show leaf node in preview window #518

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 36 additions & 12 deletions autoload/fern/scheme/file/mapping.vim
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
let s:Promise = vital#fern#import('Async.Promise')

function! fern#scheme#file#mapping#init(disable_default_mappings) abort
nnoremap <buffer><silent> <Plug>(fern-action-new-path) :<C-u>call <SID>call('new_path')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-new-file) :<C-u>call <SID>call('new_file')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-new-dir) :<C-u>call <SID>call('new_dir')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-new-path=) :<C-u>call <SID>call_without_guard('new_path')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-new-file=) :<C-u>call <SID>call_without_guard('new_file')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-new-dir=) :<C-u>call <SID>call_without_guard('new_dir')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-copy) :<C-u>call <SID>call('copy')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-move) :<C-u>call <SID>call('move')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-trash) :<C-u>call <SID>call('trash')<CR>
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-new-path) :<C-u>call <SID>call('new_path')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-new-file) :<C-u>call <SID>call('new_file')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-new-dir) :<C-u>call <SID>call('new_dir')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-new-path=) :<C-u>call <SID>call_without_guard('new_path')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-new-file=) :<C-u>call <SID>call_without_guard('new_file')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-new-dir=) :<C-u>call <SID>call_without_guard('new_dir')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-copy) :<C-u>call <SID>call('copy')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-move) :<C-u>call <SID>call('move')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-trash) :<C-u>call <SID>call('trash')<CR>
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:left) :<C-u>call <SID>call('preview', 'vertical topleft')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-preview:right) :<C-u>call <SID>call('preview', 'vertical botright')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-preview:top) :<C-u>call <SID>call('preview', 'topleft')<CR>
nnoremap <buffer><silent> <Plug>(fern-action-preview:bottom) :<C-u>call <SID>call('preview', 'botright')<CR>

" Alias map
nnoremap <buffer><silent> <Plug>(fern-action-preview) <Plug>(fern-action-preview:bottom)

if !a:disable_default_mappings
nmap <buffer><nowait> N <Plug>(fern-action-new-file)
Expand Down Expand Up @@ -205,6 +212,23 @@ function! s:map_remove(helper) abort
\.then({ -> a:helper.sync.echo(printf('%d items are removed', len(ps))) })
endfunction

function! s:map_preview(helper, prefix) 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.resolve()
endif

try
execute printf("noautocmd %s pedit %s", a:prefix, fnameescape(node._path))
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
19 changes: 17 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,19 @@ 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:left)*
*<Plug>(fern-action-preview:right)*
*<Plug>(fern-action-preview:top)*
*<Plug>(fern-action-preview:bottom)*
*<Plug>(fern-action-preview)*
Show the cursor node in a |preview-window| in similar manners of global
"open" actions.
If you would like to jump to the preview window, you can register a
mapping like:
>
nnoremap P <Plug>(fern-action-preview)<C-w>p
<

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

Expand Down
Loading