Skip to content

Commit

Permalink
Merge pull request #101 from lambdalisue/improve-rename
Browse files Browse the repository at this point in the history
Improve rename
  • Loading branch information
lambdalisue authored Jun 2, 2020
2 parents e033e22 + 8a5f90e commit ac2b757
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions autoload/fern/internal/renamer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ function! fern#internal#renamer#rename(factory, ...) abort
let options = extend({
\ 'bufname': printf('fern-renamer:%s', sha256(localtime()))[:7],
\ 'opener': 'vsplit',
\ 'cursor': [1, 1],
\ 'is_drawer': v:false,
\}, a:0 ? a:1 : {},
\)
return s:Promise.new(funcref('s:executor', [a:factory, options]))
Expand All @@ -12,6 +14,9 @@ endfunction
function! s:executor(factory, options, resolve, reject) abort
call fern#internal#buffer#open(a:options.bufname, {
\ 'opener': a:options.opener,
\ 'locator': a:options.is_drawer,
\ 'keepalt': !a:options.is_drawer && g:fern#keepalt_on_edit,
\ 'keepjumps': !a:options.is_drawer && g:fern#keepjumps_on_edit,
\ 'mods': 'noautocmd',
\})

Expand Down Expand Up @@ -47,6 +52,7 @@ function! s:executor(factory, options, resolve, reject) abort
imap <buffer> <C-m> <Plug>(fern-renamer-warn)
imap <buffer> <Return> <Plug>(fern-renamer-warn)
edit
call cursor(a:options.cursor)
endfunction

function! s:map_warn() abort
Expand Down
7 changes: 6 additions & 1 deletion autoload/fern/scheme/dict/mapping/rename.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ endfunction
function! s:map_rename(helper, opener) abort
let root = a:helper.sync.get_root_node()
let Factory = { -> map(copy(a:helper.sync.get_selected_nodes()), { _, n -> n._path }) }
let options = {
\ 'opener': a:opener,
\ 'cursor': [1, len(root._path) + 1],
\ 'is_drawer': a:helper.sync.is_drawer(),
\}
let ns = {}
return fern#internal#renamer#rename(Factory, { 'opener': a:opener })
return fern#internal#renamer#rename(Factory, options)
\.then({ r -> s:_map_rename(a:helper, r) })
\.then({ n -> s:Lambda.let(ns, 'n', n) })
\.then({ -> a:helper.async.reload_node(root.__key) })
Expand Down
7 changes: 6 additions & 1 deletion autoload/fern/scheme/file/mapping/rename.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ endfunction
function! s:map_rename(helper, opener) abort
let root = a:helper.sync.get_root_node()
let Factory = { -> map(copy(a:helper.sync.get_selected_nodes()), { _, n -> n._path }) }
let options = {
\ 'opener': a:opener,
\ 'cursor': [1, len(root._path) + 1],
\ 'is_drawer': a:helper.sync.is_drawer(),
\}
let ns = {}
return fern#internal#renamer#rename(Factory, { 'opener': a:opener })
return fern#internal#renamer#rename(Factory, options)
\.then({ r -> s:_map_rename(a:helper, r) })
\.then({ n -> s:Lambda.let(ns, 'n', n) })
\.then({ -> a:helper.async.reload_node(root.__key) })
Expand Down

0 comments on commit ac2b757

Please sign in to comment.