feature: client: vim: rr for rename file

This commit is contained in:
coderiaser 2026-05-03 16:01:46 +03:00
parent acfa27cf74
commit d82d0335b2
4 changed files with 52 additions and 25 deletions

41
HELP.md
View file

@ -214,26 +214,27 @@ Then, start the server again with `cloudcmd` and reload the page.
When the `--vim` option is provided, or the configuration parameter `vim` is set, the following hotkeys become available:
|Key |Operation
|:----------------------|:--------------------------------------------
| `j` | navigate to next file
| `k` | navigate to previous file
| `dd` | remove current file
| `G` or `$` | navigate to bottom file
| `gg` or `^` | navigate to top file
| `v` | visual mode
| `y` | copy (selected in visual mode files)
| `p` | paste files
| `Esc` | unselect all
| `/` | find file in current directory
| `n` | navigate to next found file
| `N` | navigate to previous found file
| `md` | make directory
| `mf` | make file
| `tt` | show terminal
| `e` | edit file
| `cc` | copy
| `mm` | move
| Key |Operation
|:------------|:--------------------------------------------
| `j` | navigate to next file
| `k` | navigate to previous file
| `dd` | remove current file
| `G` or `$` | navigate to bottom file
| `gg` or `^` | navigate to top file
| `v` | visual mode
| `y` | copy (selected in visual mode files)
| `p` | paste files
| `Esc` | unselect all
| `/` | find file in current directory
| `n` | navigate to next found file
| `N` | navigate to previous found file
| `md` | make directory
| `mf` | make file
| `tt` | show terminal
| `e` | edit file
| `cc` | copy
| `mm` | move
| `rr` | rename file
Commands can be joined, for example:

View file

@ -1,5 +1,3 @@
/* global CloudCmd */
/* global DOM */
import vim from './vim.js';
import * as finder from './find.js';
import {
@ -35,12 +33,13 @@ const getOperations = (event, deps) => {
prompt = globalThis.DOM.Dialog.prompt,
preventDefault = event?.preventDefault?.bind(event),
stopImmediatePropagation = event?.preventDefault?.bind(event),
promptNewFile = DOM.promptNewFile,
promptNewFile = globalThis.DOM.promptNewFile,
toggleSelectedFile,
Buffer = {},
createFindNext = _createFindNext,
createFindPrevious = _createFindPrevious,
createMakeFile = _createMakeFile,
renameCurrent,
} = deps;
return {
@ -56,7 +55,10 @@ const getOperations = (event, deps) => {
setCurrentByName,
}),
escape: unselectFiles,
rename: () => {
event.preventDefault();
renameCurrent();
},
remove: () => {
Operation.show('delete');
},
@ -72,7 +74,7 @@ const getOperations = (event, deps) => {
makeDirectory: () => {
event.stopImmediatePropagation();
event.preventDefault();
DOM.promptNewDir();
globalThis.DOM.promptNewDir();
},
terminal: () => {

View file

@ -657,3 +657,21 @@ test('cloudcmd: client: vim: edit', async (t) => {
t.calledWithNoArgs(CloudCmd.EditFileVim.show);
t.end();
});
test('cloudcmd: client: vim: rename', async (t) => {
const DOM = getDOM();
const renameCurrent = stub();
assign(DOM, {
renameCurrent,
});
const event = {
preventDefault: stub(),
};
await vim('rr', event, DOM);
t.calledWithNoArgs(renameCurrent);
t.end();
});

View file

@ -42,6 +42,7 @@ export default (key, operations = {}) => {
edit = noop,
operationCopy = noop,
operationMove = noop,
rename = noop,
} = operations;
if (key === 'Enter')
@ -128,6 +129,11 @@ export default (key, operations = {}) => {
return end();
}
if (value === 'rr') {
rename();
return end();
}
if (key === 'd' && (visual() || prevStore === 'd')) {
stopVisual();
remove();