Skip to content

Commit d82d033

Browse files
committed
feature: client: vim: rr for rename file
1 parent acfa27c commit d82d033

4 files changed

Lines changed: 52 additions & 25 deletions

File tree

HELP.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -214,26 +214,27 @@ Then, start the server again with `cloudcmd` and reload the page.
214214

215215
When the `--vim` option is provided, or the configuration parameter `vim` is set, the following hotkeys become available:
216216

217-
|Key |Operation
218-
|:----------------------|:--------------------------------------------
219-
| `j` | navigate to next file
220-
| `k` | navigate to previous file
221-
| `dd` | remove current file
222-
| `G` or `$` | navigate to bottom file
223-
| `gg` or `^` | navigate to top file
224-
| `v` | visual mode
225-
| `y` | copy (selected in visual mode files)
226-
| `p` | paste files
227-
| `Esc` | unselect all
228-
| `/` | find file in current directory
229-
| `n` | navigate to next found file
230-
| `N` | navigate to previous found file
231-
| `md` | make directory
232-
| `mf` | make file
233-
| `tt` | show terminal
234-
| `e` | edit file
235-
| `cc` | copy
236-
| `mm` | move
217+
| Key |Operation
218+
|:------------|:--------------------------------------------
219+
| `j` | navigate to next file
220+
| `k` | navigate to previous file
221+
| `dd` | remove current file
222+
| `G` or `$` | navigate to bottom file
223+
| `gg` or `^` | navigate to top file
224+
| `v` | visual mode
225+
| `y` | copy (selected in visual mode files)
226+
| `p` | paste files
227+
| `Esc` | unselect all
228+
| `/` | find file in current directory
229+
| `n` | navigate to next found file
230+
| `N` | navigate to previous found file
231+
| `md` | make directory
232+
| `mf` | make file
233+
| `tt` | show terminal
234+
| `e` | edit file
235+
| `cc` | copy
236+
| `mm` | move
237+
| `rr` | rename file
237238

238239
Commands can be joined, for example:
239240

client/key/vim/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* global CloudCmd */
2-
/* global DOM */
31
import vim from './vim.js';
42
import * as finder from './find.js';
53
import {
@@ -35,12 +33,13 @@ const getOperations = (event, deps) => {
3533
prompt = globalThis.DOM.Dialog.prompt,
3634
preventDefault = event?.preventDefault?.bind(event),
3735
stopImmediatePropagation = event?.preventDefault?.bind(event),
38-
promptNewFile = DOM.promptNewFile,
36+
promptNewFile = globalThis.DOM.promptNewFile,
3937
toggleSelectedFile,
4038
Buffer = {},
4139
createFindNext = _createFindNext,
4240
createFindPrevious = _createFindPrevious,
4341
createMakeFile = _createMakeFile,
42+
renameCurrent,
4443
} = deps;
4544

4645
return {
@@ -56,7 +55,10 @@ const getOperations = (event, deps) => {
5655
setCurrentByName,
5756
}),
5857
escape: unselectFiles,
59-
58+
rename: () => {
59+
event.preventDefault();
60+
renameCurrent();
61+
},
6062
remove: () => {
6163
Operation.show('delete');
6264
},
@@ -72,7 +74,7 @@ const getOperations = (event, deps) => {
7274
makeDirectory: () => {
7375
event.stopImmediatePropagation();
7476
event.preventDefault();
75-
DOM.promptNewDir();
77+
globalThis.DOM.promptNewDir();
7678
},
7779

7880
terminal: () => {

client/key/vim/index.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,3 +657,21 @@ test('cloudcmd: client: vim: edit', async (t) => {
657657
t.calledWithNoArgs(CloudCmd.EditFileVim.show);
658658
t.end();
659659
});
660+
661+
test('cloudcmd: client: vim: rename', async (t) => {
662+
const DOM = getDOM();
663+
const renameCurrent = stub();
664+
665+
assign(DOM, {
666+
renameCurrent,
667+
});
668+
669+
const event = {
670+
preventDefault: stub(),
671+
};
672+
673+
await vim('rr', event, DOM);
674+
675+
t.calledWithNoArgs(renameCurrent);
676+
t.end();
677+
});

client/key/vim/vim.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export default (key, operations = {}) => {
4242
edit = noop,
4343
operationCopy = noop,
4444
operationMove = noop,
45+
rename = noop,
4546
} = operations;
4647

4748
if (key === 'Enter')
@@ -128,6 +129,11 @@ export default (key, operations = {}) => {
128129
return end();
129130
}
130131

132+
if (value === 'rr') {
133+
rename();
134+
return end();
135+
}
136+
131137
if (key === 'd' && (visual() || prevStore === 'd')) {
132138
stopVisual();
133139
remove();

0 commit comments

Comments
 (0)