@@ -2,6 +2,7 @@ let s:Promise = vital#fern#import('Async.Promise')
2
2
let s: Prompt = vital#fern#import (' Prompt' )
3
3
4
4
function ! fern#scheme#file#mapping#init (disable_default_mappings) abort
5
+ nnoremap <buffer> <silent> <Plug> (fern-action-new-path) :<C-u> call <SID> call('new_path')<CR>
5
6
nnoremap <buffer> <silent> <Plug> (fern-action-new-file) :<C-u> call <SID> call('new_file')<CR>
6
7
nnoremap <buffer> <silent> <Plug> (fern-action-new-dir) :<C-u> call <SID> call('new_dir')<CR>
7
8
nnoremap <buffer> <silent> <Plug> (fern-action-copy) :<C-u> call <SID> call('copy')<CR>
@@ -48,44 +49,34 @@ function! s:map_open_system(helper) abort
48
49
\. finally ({ - > Done () })
49
50
endfunction
50
51
52
+ function ! s: map_new_path (helper) abort
53
+ let name = input (
54
+ \ " (Hint: Ends with '/' create a directory instead of a file)\n New path: " ,
55
+ \ ' ' ,
56
+ \ ' file' ,
57
+ \)
58
+ if empty (name)
59
+ return s: Promise .reject (' Cancelled' )
60
+ endif
61
+ return name[-1 :] == # ' /'
62
+ \ ? s: new_dir (a: helper , name)
63
+ \ : s: new_file (a: helper , name)
64
+ endfunction
65
+
51
66
function ! s: map_new_file (helper) abort
52
67
let name = input (' New file: ' , ' ' , ' file' )
53
68
if empty (name)
54
69
return s: Promise .reject (' Cancelled' )
55
70
endif
56
- let node = a: helper .sync .get_cursor_node ()
57
- let node = node.status isnot # a: helper .STATUS_EXPANDED ? node.__owner : node
58
- let path = fern#internal#filepath#to_slash (node._path)
59
- let path = join ([path , name], ' /' )
60
- let path = fern#internal#filepath#from_slash (path )
61
- let key = node.__key + [name]
62
- let token = a: helper .fern.source .token
63
- let previous = a: helper .sync .get_cursor_node ()
64
- return fern#scheme#file#shutil#mkfile (path , token)
65
- \. then ({ - > a: helper .async.reload_node (node.__key) })
66
- \. then ({ - > a: helper .async.reveal_node (key ) })
67
- \. then ({ - > a: helper .async.redraw () })
68
- \. then ({ - > a: helper .sync .focus_node (key , { ' previous' : previous }) })
71
+ return s: new_file (a: helper , name)
69
72
endfunction
70
73
71
74
function ! s: map_new_dir (helper) abort
72
75
let name = input (' New directory: ' , ' ' , ' dir' )
73
76
if empty (name)
74
77
return s: Promise .reject (' Cancelled' )
75
78
endif
76
- let node = a: helper .sync .get_cursor_node ()
77
- let node = node.status isnot # a: helper .STATUS_EXPANDED ? node.__owner : node
78
- let path = fern#internal#filepath#to_slash (node._path)
79
- let path = join ([path , name], ' /' )
80
- let path = fern#internal#filepath#from_slash (path )
81
- let key = node.__key + [name]
82
- let token = a: helper .fern.source .token
83
- let previous = a: helper .sync .get_cursor_node ()
84
- return fern#scheme#file#shutil#mkdir (path , token)
85
- \. then ({ - > a: helper .async.reload_node (node.__key) })
86
- \. then ({ - > a: helper .async.reveal_node (key ) })
87
- \. then ({ - > a: helper .async.redraw () })
88
- \. then ({ - > a: helper .sync .focus_node (key , { ' previous' : previous }) })
79
+ return s: new_dir (a: helper , name)
89
80
endfunction
90
81
91
82
function ! s: map_copy (helper) abort
@@ -192,6 +183,38 @@ function! s:map_remove(helper) abort
192
183
\. then ({ - > a: helper .sync .echo (printf (' %d items are removed' , len (ps ))) })
193
184
endfunction
194
185
186
+ function ! s: new_file (helper, name) abort
187
+ let node = a: helper .sync .get_cursor_node ()
188
+ let node = node.status isnot # a: helper .STATUS_EXPANDED ? node.__owner : node
189
+ let path = fern#internal#filepath#to_slash (node._path)
190
+ let path = join ([path , a: name ], ' /' )
191
+ let path = fern#internal#filepath#from_slash (path )
192
+ let key = node.__key + [a: name ]
193
+ let token = a: helper .fern.source .token
194
+ let previous = a: helper .sync .get_cursor_node ()
195
+ return fern#scheme#file#shutil#mkfile (path , token)
196
+ \. then ({ - > a: helper .async.reload_node (node.__key) })
197
+ \. then ({ - > a: helper .async.reveal_node (key ) })
198
+ \. then ({ - > a: helper .async.redraw () })
199
+ \. then ({ - > a: helper .sync .focus_node (key , { ' previous' : previous }) })
200
+ endfunction
201
+
202
+ function ! s: new_dir (helper, name) abort
203
+ let node = a: helper .sync .get_cursor_node ()
204
+ let node = node.status isnot # a: helper .STATUS_EXPANDED ? node.__owner : node
205
+ let path = fern#internal#filepath#to_slash (node._path)
206
+ let path = join ([path , a: name ], ' /' )
207
+ let path = fern#internal#filepath#from_slash (path )
208
+ let key = node.__key + [a: name ]
209
+ let token = a: helper .fern.source .token
210
+ let previous = a: helper .sync .get_cursor_node ()
211
+ return fern#scheme#file#shutil#mkdir (path , token)
212
+ \. then ({ - > a: helper .async.reload_node (node.__key) })
213
+ \. then ({ - > a: helper .async.reveal_node (key ) })
214
+ \. then ({ - > a: helper .async.redraw () })
215
+ \. then ({ - > a: helper .sync .focus_node (key , { ' previous' : previous }) })
216
+ endfunction
217
+
195
218
let g: fern #scheme#file #mapping #mappings = get (g: , ' fern#scheme#file#mapping#mappings' , [
196
219
\ ' cd' ,
197
220
\ ' clipboard' ,
0 commit comments