feature: client: vim: add ability to create directory with 'md', and create file with 'mf'

This commit is contained in:
coderaiser 2023-01-29 13:41:12 +02:00
parent 31e1eeea50
commit 4a38c64cd6
5 changed files with 90 additions and 1 deletions

View file

@ -220,6 +220,8 @@ When the `--vim` option is provided, or the configuration parameter `vim` is set
| `/` | find file in current directory
| `n` | navigate to next found file
| `N` | navigate to previous found file
| `md` | make directory
| `mf` | make file
Commands can be joined, for example:

View file

@ -29,6 +29,8 @@ module.exports.getDOM = () => {
getCurrentName: noop,
setCurrentByName: noop,
toggleSelectedFile: noop,
prompNewDirectory: noop,
promptNewFile: noop,
};
};

View file

@ -21,6 +21,18 @@ const getOperations = (event) => ({
CloudCmd.Operation.show('delete');
},
makeDirectory: () => {
event.stopImmediatePropagation();
event.preventDefault();
DOM.promptNewDir();
},
makeFile: () => {
event.stopImmediatePropagation();
event.preventDefault();
DOM.promptNewFile();
},
copy: () => {
DOM.Buffer.copy();
DOM.unselectFiles();

View file

@ -22,6 +22,7 @@ global.CloudCmd = getCloudCmd();
const vim = require(pathVim);
const {assign} = Object;
const {DOM} = global;
const {Buffer} = DOM;
@ -405,7 +406,31 @@ test('cloudcmd: client: key: /', (t) => {
preventDefault,
});
t.ok(preventDefault.calledWith(), 'should call preventDefault');
t.calledWithNoArgs(preventDefault, 'should call preventDefault');
t.end();
});
test('cloudcmd: client: find', (t) => {
assign(DOM.Dialog, {
prompt: stub().returns([]),
});
const setCurrentByName = stub();
assign(DOM, {
setCurrentByName,
});
const vim = reRequire(pathVim);
const event = {
preventDefault: stub(),
};
vim('/', event);
stopAll();
t.notCalled(setCurrentByName);
t.end();
});
@ -445,3 +470,39 @@ test('cloudcmd: client: key: N', (t) => {
t.end();
});
test('cloudcmd: client: key: make directory', (t) => {
const vim = reRequire(pathVim);
assign(DOM, {
promptNewDir: stub(),
});
const event = {
stopImmediatePropagation: stub(),
preventDefault: stub(),
};
vim('m', event);
vim('d', event);
t.calledWithNoArgs(DOM.promptNewDir);
t.end();
});
test('cloudcmd: client: key: make file', (t) => {
const vim = reRequire(pathVim);
assign(DOM, {
promptNewFile: stub(),
});
const event = {
stopImmediatePropagation: stub(),
preventDefault: stub(),
};
vim('m', event);
vim('f', event);
t.calledWithNoArgs(DOM.promptNewDir);
t.end();
});

View file

@ -36,6 +36,8 @@ module.exports = (key, operations) => {
find = noop,
findNext = noop,
findPrevious = noop,
makeFile = noop,
makeDirectory = noop,
} = operations;
if (key === 'Enter')
@ -95,6 +97,16 @@ module.exports = (key, operations) => {
return end();
}
if (value === 'md') {
makeDirectory();
return end();
}
if (value === 'mf') {
makeFile();
return end();
}
if (key === 'd' && (visual() || prevStore === 'd')) {
stopVisual();
remove();