From 3df242c3bf8564f88adaab73e1efe5162100b41e Mon Sep 17 00:00:00 2001 From: lambdalisue Date: Thu, 11 Jun 2020 12:24:33 +0900 Subject: [PATCH] Improve cd/lcd/tcd action in file scheme - Add cd:root/lcd:root/tcd:root action to perform cd/lcd/tcd on root node - Add cd:cursor/lcd:cursor/tcd:cursor action to perform cd/lcd/tcd on cursor node - Alias cd/lcd/tcd to cd:cursor/lcd:cursor/tcd:cursor for backward compatibility --- autoload/fern/scheme/file/mapping/cd.vim | 28 ++++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/autoload/fern/scheme/file/mapping/cd.vim b/autoload/fern/scheme/file/mapping/cd.vim index 76556213..44ad34cc 100644 --- a/autoload/fern/scheme/file/mapping/cd.vim +++ b/autoload/fern/scheme/file/mapping/cd.vim @@ -1,9 +1,16 @@ let s:Promise = vital#fern#import('Async.Promise') function! fern#scheme#file#mapping#cd#init(disable_default_mappings) abort - nnoremap (fern-action-cd) :call call('cd', 'cd') - nnoremap (fern-action-lcd) :call call('cd', 'lcd') - nnoremap (fern-action-tcd) :call call('cd', 'tcd') + nnoremap (fern-action-cd:root) :call call('cd_root', 'cd') + nnoremap (fern-action-lcd:root) :call call('cd_root', 'lcd') + nnoremap (fern-action-tcd:root) :call call('cd_root', 'tcd') + nnoremap (fern-action-cd:cursor) :call call('cd_cursor', 'cd') + nnoremap (fern-action-lcd:cursor) :call call('cd_cursor', 'lcd') + nnoremap (fern-action-tcd:cursor) :call call('cd_cursor', 'tcd') + + nmap (fern-action-cd) (fern-action-cd:cursor) + nmap (fern-action-lcd) (fern-action-lcd:cursor) + nmap (fern-action-tcd) (fern-action-tcd:cursor) endfunction function! s:call(name, ...) abort @@ -13,17 +20,24 @@ function! s:call(name, ...) abort \) endfunction -function! s:map_cd(helper, command) abort - let node = a:helper.sync.get_cursor_node() +function! s:map_cd_root(helper, command) abort + return s:cd(a:helper.sync.get_root_node(), a:helper, a:command) +endfunction + +function! s:map_cd_cursor(helper, command) abort + return s:cd(a:helper.sync.get_cursor_node(), a:helper, a:command) +endfunction + +function! s:cd(node, helper, command) abort if a:command ==# 'tcd' && !exists(':tcd') let winid = win_getid() silent execute printf( \ 'keepalt keepjumps %d,%dwindo lcd %s', - \ 1, winnr('$'), fnameescape(node._path), + \ 1, winnr('$'), fnameescape(a:node._path), \) call win_gotoid(winid) else - execute a:command fnameescape(node._path) + execute a:command fnameescape(a:node._path) endif return s:Promise.resolve() endfunction