diff --git a/HELP.md b/HELP.md index 1e31de4b..3dae2334 100644 --- a/HELP.md +++ b/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: diff --git a/client/key/vim/globals.fixture.js b/client/key/vim/globals.fixture.js index ec1fbbcf..9f2f63b4 100644 --- a/client/key/vim/globals.fixture.js +++ b/client/key/vim/globals.fixture.js @@ -29,6 +29,8 @@ module.exports.getDOM = () => { getCurrentName: noop, setCurrentByName: noop, toggleSelectedFile: noop, + prompNewDirectory: noop, + promptNewFile: noop, }; }; diff --git a/client/key/vim/index.js b/client/key/vim/index.js index a0831773..78998f42 100644 --- a/client/key/vim/index.js +++ b/client/key/vim/index.js @@ -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(); diff --git a/client/key/vim/index.spec.js b/client/key/vim/index.spec.js index f0ed9b58..cb8e3d7d 100644 --- a/client/key/vim/index.spec.js +++ b/client/key/vim/index.spec.js @@ -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(); +}); + diff --git a/client/key/vim/vim.js b/client/key/vim/vim.js index f1ca62a4..9f60b76f 100644 --- a/client/key/vim/vim.js +++ b/client/key/vim/vim.js @@ -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();