mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature: client: vim: add ability to create directory with 'md', and create file with 'mf'
This commit is contained in:
parent
31e1eeea50
commit
4a38c64cd6
5 changed files with 90 additions and 1 deletions
2
HELP.md
2
HELP.md
|
|
@ -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:
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ module.exports.getDOM = () => {
|
|||
getCurrentName: noop,
|
||||
setCurrentByName: noop,
|
||||
toggleSelectedFile: noop,
|
||||
prompNewDirectory: noop,
|
||||
promptNewFile: noop,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue