mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
chore: lint
This commit is contained in:
parent
f1279666b5
commit
4717e035ee
173 changed files with 1388 additions and 1627 deletions
|
|
@ -15,4 +15,3 @@ module.exports.createBinder = () => {
|
|||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
/* global CloudCmd, DOM */
|
||||
|
||||
const clipboard = require('@cloudcmd/clipboard');
|
||||
|
||||
const Buffer = require('../dom/buffer');
|
||||
|
|
@ -32,6 +31,7 @@ Chars([]);
|
|||
const {assign} = Object;
|
||||
|
||||
const binder = createBinder();
|
||||
|
||||
module.exports = assign(binder, KEY);
|
||||
module.exports.bind = () => {
|
||||
Events.addKey(listener, true);
|
||||
|
|
@ -45,13 +45,13 @@ function getChar(event) {
|
|||
* event.keyIdentifier deprecated in chrome v51
|
||||
* but event.key is absent in chrome <= v51
|
||||
*/
|
||||
|
||||
const {
|
||||
key,
|
||||
shift,
|
||||
keyCode,
|
||||
keyIdentifier,
|
||||
} = event;
|
||||
|
||||
const char = key || fromCharCode(keyIdentifier);
|
||||
const symbol = getSymbol(shift, keyCode);
|
||||
|
||||
|
|
@ -136,6 +136,7 @@ async function switchKey(event) {
|
|||
changeDir,
|
||||
config,
|
||||
} = CloudCmd;
|
||||
|
||||
const {keyCode} = event;
|
||||
|
||||
const alt = event.altKey;
|
||||
|
|
@ -156,12 +157,14 @@ async function switchKey(event) {
|
|||
break;
|
||||
|
||||
case KEY.INSERT:
|
||||
DOM .toggleSelectedFile(current)
|
||||
DOM
|
||||
.toggleSelectedFile(current)
|
||||
.setCurrentFile(next);
|
||||
break;
|
||||
|
||||
case KEY.INSERT_MAC:
|
||||
DOM .toggleSelectedFile(current)
|
||||
DOM
|
||||
.toggleSelectedFile(current)
|
||||
.setCurrentFile(next);
|
||||
break;
|
||||
|
||||
|
|
@ -170,7 +173,7 @@ async function switchKey(event) {
|
|||
Operation.show('delete:silent');
|
||||
else
|
||||
Operation.show('delete');
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case KEY.ASTERISK:
|
||||
|
|
@ -305,7 +308,7 @@ async function switchKey(event) {
|
|||
DOM.swapPanels();
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
|
||||
/* navigation on file table: *
|
||||
|
|
@ -403,7 +406,7 @@ async function switchKey(event) {
|
|||
await changeDir(path);
|
||||
else
|
||||
CloudCmd.View.show();
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case KEY.BACKSPACE:
|
||||
|
|
@ -414,7 +417,7 @@ async function switchKey(event) {
|
|||
case KEY.BACKSLASH:
|
||||
if (ctrlMeta)
|
||||
await changeDir('/');
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case KEY.A:
|
||||
|
|
@ -455,6 +458,7 @@ async function switchKey(event) {
|
|||
.catch(CloudCmd.log);
|
||||
|
||||
break;
|
||||
|
||||
/**
|
||||
* обновляем страницу,
|
||||
* загружаем содержимое каталога
|
||||
|
|
@ -468,31 +472,31 @@ async function switchKey(event) {
|
|||
CloudCmd.refresh();
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case KEY.C:
|
||||
if (ctrlMeta)
|
||||
Buffer.copy();
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case KEY.X:
|
||||
if (ctrlMeta)
|
||||
Buffer.cut();
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case KEY.V:
|
||||
if (ctrlMeta)
|
||||
Buffer.paste();
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case KEY.Z:
|
||||
if (ctrlMeta)
|
||||
Buffer.clear();
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case KEY.COLON:
|
||||
|
|
@ -508,8 +512,7 @@ async function switchKey(event) {
|
|||
CloudCmd.log('storage cleared');
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,8 @@ const autoGlobals = require('auto-globals');
|
|||
const stub = require('@cloudcmd/stub');
|
||||
const mockRequire = require('mock-require');
|
||||
const {ESC} = require('./key');
|
||||
const {
|
||||
getDOM,
|
||||
getCloudCmd,
|
||||
} = require('./vim/globals.fixture');
|
||||
|
||||
const {getDOM, getCloudCmd} = require('./vim/globals.fixture');
|
||||
|
||||
const {reRequire, stopAll} = mockRequire;
|
||||
|
||||
|
|
@ -66,4 +64,3 @@ test('cloudcmd: client: key: disable vim', async (t) => {
|
|||
t.calledWith(_config, ['vim']);
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,81 +1,81 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
BACKSPACE : 8,
|
||||
TAB : 9,
|
||||
ENTER : 13,
|
||||
CAPSLOCK : 20,
|
||||
ESC : 27,
|
||||
BACKSPACE: 8,
|
||||
TAB: 9,
|
||||
ENTER: 13,
|
||||
CAPSLOCK: 20,
|
||||
ESC: 27,
|
||||
|
||||
SPACE : 32,
|
||||
PAGE_UP : 33,
|
||||
PAGE_DOWN : 34,
|
||||
END : 35,
|
||||
HOME : 36,
|
||||
SPACE: 32,
|
||||
PAGE_UP: 33,
|
||||
PAGE_DOWN: 34,
|
||||
END: 35,
|
||||
HOME: 36,
|
||||
|
||||
LEFT : 37,
|
||||
UP : 38,
|
||||
RIGHT : 39,
|
||||
DOWN : 40,
|
||||
LEFT: 37,
|
||||
UP: 38,
|
||||
RIGHT: 39,
|
||||
DOWN: 40,
|
||||
|
||||
INSERT : 45,
|
||||
DELETE : 46,
|
||||
INSERT: 45,
|
||||
DELETE: 46,
|
||||
|
||||
ZERO : 48,
|
||||
ZERO: 48,
|
||||
|
||||
SEMICOLON : 52,
|
||||
SEMICOLON: 52,
|
||||
|
||||
A : 65,
|
||||
A: 65,
|
||||
|
||||
C : 67,
|
||||
D : 68,
|
||||
C: 67,
|
||||
D: 68,
|
||||
|
||||
G : 71,
|
||||
G: 71,
|
||||
|
||||
J : 74,
|
||||
K : 75,
|
||||
J: 74,
|
||||
K: 75,
|
||||
|
||||
M : 77,
|
||||
M: 77,
|
||||
|
||||
O : 79,
|
||||
P : 80,
|
||||
Q : 81,
|
||||
R : 82,
|
||||
S : 83,
|
||||
T : 84,
|
||||
U : 85,
|
||||
O: 79,
|
||||
P: 80,
|
||||
Q: 81,
|
||||
R: 82,
|
||||
S: 83,
|
||||
T: 84,
|
||||
U: 85,
|
||||
|
||||
V : 86,
|
||||
V: 86,
|
||||
|
||||
X : 88,
|
||||
X: 88,
|
||||
|
||||
Z : 90,
|
||||
Z: 90,
|
||||
|
||||
INSERT_MAC : 96,
|
||||
INSERT_MAC: 96,
|
||||
|
||||
ASTERISK : 106,
|
||||
PLUS : 107,
|
||||
MINUS : 109,
|
||||
ASTERISK: 106,
|
||||
PLUS: 107,
|
||||
MINUS: 109,
|
||||
|
||||
F1 : 112,
|
||||
F2 : 113,
|
||||
F3 : 114,
|
||||
F4 : 115,
|
||||
F5 : 116,
|
||||
F6 : 117,
|
||||
F7 : 118,
|
||||
F8 : 119,
|
||||
F9 : 120,
|
||||
F10 : 121,
|
||||
F1: 112,
|
||||
F2: 113,
|
||||
F3: 114,
|
||||
F4: 115,
|
||||
F5: 116,
|
||||
F6: 117,
|
||||
F7: 118,
|
||||
F8: 119,
|
||||
F9: 120,
|
||||
F10: 121,
|
||||
|
||||
COLON : 186,
|
||||
EQUAL : 187,
|
||||
HYPHEN : 189,
|
||||
DOT : 190,
|
||||
SLASH : 191,
|
||||
TRA : 192, /* Typewritten Reverse Apostrophe (`) */
|
||||
BACKSLASH : 220,
|
||||
COLON: 186,
|
||||
EQUAL: 187,
|
||||
HYPHEN: 189,
|
||||
DOT: 190,
|
||||
SLASH: 191,
|
||||
/* Typewritten Reverse Apostrophe (`) */
|
||||
TRA: 192,
|
||||
BACKSLASH: 220,
|
||||
|
||||
BRACKET_CLOSE: 221,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ module.exports = function setCurrentByChar(char, charStore) {
|
|||
const isTest = (a) => regExp.test(a);
|
||||
const isRoot = (a) => a === '..';
|
||||
const not = (f) => (a) => !f(a);
|
||||
|
||||
const setCurrent = (name) => {
|
||||
const byName = DOM.getCurrentByName(name);
|
||||
|
||||
|
|
@ -57,4 +58,3 @@ module.exports = function setCurrentByChar(char, charStore) {
|
|||
charStore([char]);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -37,14 +37,13 @@ module.exports._previous = previous;
|
|||
function next(index, length) {
|
||||
if (index === length - 1)
|
||||
return 0;
|
||||
|
||||
|
||||
return ++index;
|
||||
}
|
||||
|
||||
function previous(index, length) {
|
||||
if (!index)
|
||||
return length - 1;
|
||||
|
||||
|
||||
return --index;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,10 +7,7 @@ const {getDOM} = require('./globals.fixture');
|
|||
|
||||
global.DOM = getDOM();
|
||||
|
||||
const {
|
||||
_next,
|
||||
_previous,
|
||||
} = require(`${dir}find`);
|
||||
const {_next, _previous} = require(`${dir}find`);
|
||||
|
||||
test('cloudcmd: client: vim: _next', (t) => {
|
||||
const result = _next(1, 2);
|
||||
|
|
@ -25,4 +22,3 @@ test('cloudcmd: client: vim: _previous', (t) => {
|
|||
t.equal(result, 1, 'should return 1');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ module.exports.getCloudCmd = () => {
|
|||
const show = () => {};
|
||||
|
||||
return {
|
||||
Operation: {
|
||||
Operation: {
|
||||
show,
|
||||
},
|
||||
|
||||
|
|
@ -46,4 +46,3 @@ module.exports.getCloudCmd = () => {
|
|||
_config: noop,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
/* global CloudCmd */
|
||||
/* global DOM */
|
||||
|
||||
const vim = require('./vim');
|
||||
const finder = require('./find');
|
||||
|
||||
|
|
@ -16,43 +15,43 @@ module.exports = async (key, event) => {
|
|||
|
||||
const getOperations = (event) => ({
|
||||
escape: DOM.unselectFiles,
|
||||
|
||||
|
||||
remove: () => {
|
||||
CloudCmd.Operation.show('delete');
|
||||
},
|
||||
|
||||
|
||||
makeDirectory: () => {
|
||||
event.stopImmediatePropagation();
|
||||
event.preventDefault();
|
||||
DOM.promptNewDir();
|
||||
},
|
||||
|
||||
|
||||
makeFile: () => {
|
||||
event.stopImmediatePropagation();
|
||||
event.preventDefault();
|
||||
DOM.promptNewFile();
|
||||
},
|
||||
|
||||
|
||||
terminal: () => {
|
||||
CloudCmd.Terminal.show();
|
||||
},
|
||||
|
||||
|
||||
edit: () => {
|
||||
CloudCmd.EditFileVim.show();
|
||||
},
|
||||
|
||||
|
||||
copy: () => {
|
||||
DOM.Buffer.copy();
|
||||
DOM.unselectFiles();
|
||||
},
|
||||
|
||||
|
||||
select: () => {
|
||||
const current = Info.element;
|
||||
DOM.toggleSelectedFile(current);
|
||||
},
|
||||
|
||||
|
||||
paste: DOM.Buffer.paste,
|
||||
|
||||
|
||||
moveNext: ({count, isVisual, isDelete}) => {
|
||||
setCurrent('next', {
|
||||
count,
|
||||
|
|
@ -60,7 +59,7 @@ const getOperations = (event) => ({
|
|||
isDelete,
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
movePrevious: ({count, isVisual, isDelete}) => {
|
||||
setCurrent('previous', {
|
||||
count,
|
||||
|
|
@ -68,25 +67,25 @@ const getOperations = (event) => ({
|
|||
isDelete,
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
find: async () => {
|
||||
event.preventDefault();
|
||||
const [, value] = await Dialog.prompt('Find', '');
|
||||
|
||||
|
||||
if (!value)
|
||||
return;
|
||||
|
||||
|
||||
const names = Info.files.map(DOM.getCurrentName);
|
||||
const [result] = finder.find(value, names);
|
||||
|
||||
|
||||
DOM.setCurrentByName(result);
|
||||
},
|
||||
|
||||
|
||||
findNext: () => {
|
||||
const name = finder.findNext();
|
||||
DOM.setCurrentByName(name);
|
||||
},
|
||||
|
||||
|
||||
findPrevious: () => {
|
||||
const name = finder.findPrevious();
|
||||
DOM.setCurrentByName(name);
|
||||
|
|
@ -97,34 +96,33 @@ module.exports.selectFile = selectFile;
|
|||
|
||||
function selectFile(current) {
|
||||
const name = DOM.getCurrentName(current);
|
||||
|
||||
|
||||
if (name === '..')
|
||||
return;
|
||||
|
||||
|
||||
DOM.selectFile(current);
|
||||
}
|
||||
|
||||
function setCurrent(sibling, {count, isVisual, isDelete}) {
|
||||
let current = Info.element;
|
||||
const select = isVisual ? selectFile : DOM.unselectFile;
|
||||
|
||||
|
||||
select(current);
|
||||
|
||||
|
||||
const position = `${sibling}Sibling`;
|
||||
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const next = current[position];
|
||||
|
||||
|
||||
if (!next)
|
||||
break;
|
||||
|
||||
|
||||
current = next;
|
||||
select(current);
|
||||
}
|
||||
|
||||
|
||||
DOM.setCurrentFile(current);
|
||||
|
||||
|
||||
if (isDelete)
|
||||
CloudCmd.Operation.show('delete');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,20 +2,15 @@
|
|||
|
||||
const {join} = require('path');
|
||||
|
||||
const {
|
||||
test,
|
||||
stub,
|
||||
} = require('supertape');
|
||||
const {test, stub} = require('supertape');
|
||||
|
||||
const mockRequire = require('mock-require');
|
||||
|
||||
const dir = '../';
|
||||
|
||||
const pathVim = join(dir, 'vim');
|
||||
|
||||
const {
|
||||
getDOM,
|
||||
getCloudCmd,
|
||||
} = require('./globals.fixture');
|
||||
const {getDOM, getCloudCmd} = require('./globals.fixture');
|
||||
|
||||
global.DOM = getDOM();
|
||||
global.CloudCmd = getCloudCmd();
|
||||
|
|
@ -23,10 +18,7 @@ global.CloudCmd = getCloudCmd();
|
|||
const vim = require(pathVim);
|
||||
|
||||
const {assign} = Object;
|
||||
const {
|
||||
DOM,
|
||||
CloudCmd,
|
||||
} = global;
|
||||
const {DOM, CloudCmd} = global;
|
||||
|
||||
const {Buffer} = DOM;
|
||||
const pathFind = join(dir, 'vim', 'find');
|
||||
|
|
@ -34,14 +26,14 @@ const {reRequire, stopAll} = mockRequire;
|
|||
|
||||
test('cloudcmd: client: key: set next file: no', (t) => {
|
||||
const element = {};
|
||||
|
||||
|
||||
const setCurrentFile = stub();
|
||||
|
||||
|
||||
global.DOM.CurrentInfo.element = element;
|
||||
global.DOM.setCurrentFile = setCurrentFile;
|
||||
|
||||
|
||||
vim('j', {});
|
||||
|
||||
|
||||
t.calledWith(setCurrentFile, [element], 'should set next file');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -51,14 +43,14 @@ test('cloudcmd: client: key: set next file current: j', (t) => {
|
|||
const element = {
|
||||
nextSibling,
|
||||
};
|
||||
|
||||
|
||||
const setCurrentFile = stub();
|
||||
|
||||
|
||||
global.DOM.CurrentInfo.element = element;
|
||||
global.DOM.setCurrentFile = setCurrentFile;
|
||||
|
||||
|
||||
vim('j', {});
|
||||
|
||||
|
||||
t.calledWith(setCurrentFile, [nextSibling], 'should set next file');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -68,16 +60,16 @@ test('cloudcmd: client: key: set next file current: mjj', (t) => {
|
|||
const element = {
|
||||
nextSibling,
|
||||
};
|
||||
|
||||
|
||||
const setCurrentFile = stub();
|
||||
|
||||
|
||||
global.DOM.CurrentInfo.element = element;
|
||||
global.DOM.setCurrentFile = setCurrentFile;
|
||||
|
||||
|
||||
vim('m', {});
|
||||
vim('j', {});
|
||||
vim('j', {});
|
||||
|
||||
|
||||
t.calledWith(setCurrentFile, [nextSibling], 'should set next file');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -87,15 +79,15 @@ test('cloudcmd: client: key: set next file current: g', (t) => {
|
|||
const element = {
|
||||
nextSibling,
|
||||
};
|
||||
|
||||
|
||||
const setCurrentFile = stub();
|
||||
|
||||
|
||||
global.DOM.CurrentInfo.element = element;
|
||||
global.DOM.setCurrentFile = setCurrentFile;
|
||||
|
||||
|
||||
vim('g', {});
|
||||
vim('j', {});
|
||||
|
||||
|
||||
t.calledWith(setCurrentFile, [nextSibling], 'should ignore g');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -105,20 +97,21 @@ test('cloudcmd: client: key: set +2 file current', (t) => {
|
|||
const nextSibling = {
|
||||
nextSibling: last,
|
||||
};
|
||||
|
||||
const element = {
|
||||
nextSibling,
|
||||
};
|
||||
|
||||
|
||||
const setCurrentFile = stub();
|
||||
|
||||
|
||||
global.DOM.CurrentInfo.element = element;
|
||||
global.DOM.setCurrentFile = setCurrentFile;
|
||||
|
||||
|
||||
const event = {};
|
||||
|
||||
|
||||
vim('2', event);
|
||||
vim('j', event);
|
||||
|
||||
|
||||
t.calledWith(setCurrentFile, [last], 'should set next file');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -128,24 +121,25 @@ test('cloudcmd: client: key: select +2 files from current before delete', (t) =>
|
|||
const nextSibling = {
|
||||
nextSibling: last,
|
||||
};
|
||||
|
||||
const element = {
|
||||
nextSibling,
|
||||
};
|
||||
|
||||
|
||||
const setCurrentFile = stub();
|
||||
|
||||
|
||||
global.DOM.CurrentInfo.element = element;
|
||||
global.DOM.setCurrentFile = setCurrentFile;
|
||||
global.DOM.selectFile = stub();
|
||||
global.DOM.getCurrentName = () => false;
|
||||
global.CloudCmd.Operation.show = stub();
|
||||
|
||||
|
||||
const event = {};
|
||||
|
||||
|
||||
vim('d', event);
|
||||
vim('2', event);
|
||||
vim('j', event);
|
||||
|
||||
|
||||
t.calledWith(setCurrentFile, [last], 'should set next file');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -155,25 +149,26 @@ test('cloudcmd: client: key: delete +2 files from current', (t) => {
|
|||
const nextSibling = {
|
||||
nextSibling: last,
|
||||
};
|
||||
|
||||
const element = {
|
||||
nextSibling,
|
||||
};
|
||||
|
||||
|
||||
const setCurrentFile = stub();
|
||||
const show = stub();
|
||||
|
||||
|
||||
global.DOM.CurrentInfo.element = element;
|
||||
global.DOM.setCurrentFile = setCurrentFile;
|
||||
global.DOM.selectFile = stub();
|
||||
global.DOM.getCurrentName = () => false;
|
||||
global.CloudCmd.Operation.show = show;
|
||||
|
||||
|
||||
const event = {};
|
||||
|
||||
|
||||
vim('d', event);
|
||||
vim('2', event);
|
||||
vim('j', event);
|
||||
|
||||
|
||||
t.calledWith(show, ['delete'], 'should call delete');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -183,87 +178,87 @@ test('cloudcmd: client: key: set previous file current', (t) => {
|
|||
const element = {
|
||||
previousSibling,
|
||||
};
|
||||
|
||||
|
||||
const setCurrentFile = stub();
|
||||
|
||||
|
||||
global.DOM.CurrentInfo.element = element;
|
||||
global.DOM.setCurrentFile = setCurrentFile;
|
||||
|
||||
|
||||
vim('k', {});
|
||||
|
||||
|
||||
t.calledWith(setCurrentFile, [previousSibling], 'should set previous file');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: key: copy: no', (t) => {
|
||||
const copy = stub();
|
||||
|
||||
|
||||
Buffer.copy = copy;
|
||||
|
||||
|
||||
vim('y', {});
|
||||
|
||||
|
||||
t.notOk(copy.called, 'should not copy files');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: key: copy', (t) => {
|
||||
const copy = stub();
|
||||
|
||||
|
||||
Buffer.copy = copy;
|
||||
|
||||
|
||||
vim('v', {});
|
||||
vim('y', {});
|
||||
|
||||
|
||||
t.ok(copy.calledWith(), 'should copy files');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: key: copy: unselectFiles', (t) => {
|
||||
const unselectFiles = stub();
|
||||
|
||||
|
||||
DOM.unselectFiles = unselectFiles;
|
||||
|
||||
|
||||
vim('v', {});
|
||||
vim('y', {});
|
||||
|
||||
|
||||
t.ok(unselectFiles.calledWith(), 'should unselect files');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: key: paste', (t) => {
|
||||
const paste = stub();
|
||||
|
||||
|
||||
Buffer.paste = paste;
|
||||
|
||||
|
||||
vim('p', {});
|
||||
|
||||
|
||||
t.ok(paste.calledWith(), 'should paste files');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: key: selectFile: ..', (t) => {
|
||||
const getCurrentName = stub();
|
||||
|
||||
|
||||
DOM.selectFile = stub();
|
||||
DOM.getCurrentName = () => '..';
|
||||
|
||||
|
||||
const current = {};
|
||||
vim.selectFile(current);
|
||||
|
||||
|
||||
t.notOk(getCurrentName.called, 'should not call selectFile');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: key: selectFile', (t) => {
|
||||
const selectFile = stub();
|
||||
|
||||
|
||||
DOM.selectFile = selectFile;
|
||||
DOM.getCurrentName = (a) => a.name;
|
||||
|
||||
|
||||
const current = {};
|
||||
|
||||
|
||||
vim.selectFile(current);
|
||||
|
||||
|
||||
t.calledWith(selectFile, [current], 'should call selectFile');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -273,17 +268,18 @@ test('cloudcmd: client: key: set last file current: shift + g', (t) => {
|
|||
const nextSibling = {
|
||||
nextSibling: last,
|
||||
};
|
||||
|
||||
const element = {
|
||||
nextSibling,
|
||||
};
|
||||
|
||||
|
||||
const setCurrentFile = stub();
|
||||
|
||||
|
||||
global.DOM.CurrentInfo.element = element;
|
||||
global.DOM.setCurrentFile = setCurrentFile;
|
||||
|
||||
|
||||
vim('G', {});
|
||||
|
||||
|
||||
t.calledWith(setCurrentFile, [last], 'should set last file');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -293,17 +289,18 @@ test('cloudcmd: client: key: set last file current: $', (t) => {
|
|||
const nextSibling = {
|
||||
nextSibling: last,
|
||||
};
|
||||
|
||||
const element = {
|
||||
nextSibling,
|
||||
};
|
||||
|
||||
|
||||
const setCurrentFile = stub();
|
||||
|
||||
|
||||
global.DOM.CurrentInfo.element = element;
|
||||
global.DOM.setCurrentFile = setCurrentFile;
|
||||
|
||||
|
||||
vim('$', {});
|
||||
|
||||
|
||||
t.calledWith(setCurrentFile, [last], 'should set last file');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -313,19 +310,19 @@ test('cloudcmd: client: key: set first file current: gg', (t) => {
|
|||
const previousSibling = {
|
||||
previousSibling: first,
|
||||
};
|
||||
|
||||
|
||||
const element = {
|
||||
previousSibling,
|
||||
};
|
||||
|
||||
|
||||
const setCurrentFile = stub();
|
||||
|
||||
|
||||
global.DOM.CurrentInfo.element = element;
|
||||
global.DOM.setCurrentFile = setCurrentFile;
|
||||
|
||||
|
||||
vim('g', {});
|
||||
vim('g', {});
|
||||
|
||||
|
||||
t.calledWith(setCurrentFile, [first], 'should set first file');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -335,46 +332,46 @@ test('cloudcmd: client: key: set first file current: ^', (t) => {
|
|||
const previousSibling = {
|
||||
previousSibling: first,
|
||||
};
|
||||
|
||||
|
||||
const element = {
|
||||
previousSibling,
|
||||
};
|
||||
|
||||
|
||||
const setCurrentFile = stub();
|
||||
|
||||
|
||||
global.DOM.CurrentInfo.element = element;
|
||||
global.DOM.setCurrentFile = setCurrentFile;
|
||||
|
||||
|
||||
vim('^', {});
|
||||
|
||||
|
||||
t.calledWith(setCurrentFile, [first], 'should set first file');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: key: visual', (t) => {
|
||||
const element = {};
|
||||
|
||||
|
||||
const toggleSelectedFile = stub();
|
||||
|
||||
|
||||
global.DOM.CurrentInfo.element = element;
|
||||
global.DOM.toggleSelectedFile = toggleSelectedFile;
|
||||
|
||||
|
||||
vim('v', {});
|
||||
|
||||
|
||||
t.calledWith(toggleSelectedFile, [element], 'should toggle selection');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: key: ESC', (t) => {
|
||||
const element = {};
|
||||
|
||||
|
||||
const unselectFiles = stub();
|
||||
|
||||
|
||||
global.DOM.CurrentInfo.element = element;
|
||||
global.DOM.unselectFiles = unselectFiles ;
|
||||
|
||||
global.DOM.unselectFiles = unselectFiles;
|
||||
|
||||
vim('Escape');
|
||||
|
||||
|
||||
t.ok(unselectFiles.calledWith(), 'should toggle selection');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -384,16 +381,16 @@ test('cloudcmd: client: key: Enter', (t) => {
|
|||
const element = {
|
||||
nextSibling,
|
||||
};
|
||||
|
||||
|
||||
const setCurrentFile = stub();
|
||||
|
||||
|
||||
DOM.CurrentInfo.element = element;
|
||||
DOM.setCurrentFile = setCurrentFile;
|
||||
|
||||
|
||||
vim('Enter');
|
||||
|
||||
|
||||
vim('j');
|
||||
|
||||
|
||||
t.calledWith(setCurrentFile, [nextSibling], 'should set next file');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -401,14 +398,14 @@ test('cloudcmd: client: key: Enter', (t) => {
|
|||
test('cloudcmd: client: key: /', (t) => {
|
||||
const preventDefault = stub();
|
||||
const element = {};
|
||||
|
||||
|
||||
DOM.CurrentInfo.element = element;
|
||||
DOM.getCurrentName = () => '';
|
||||
|
||||
|
||||
vim('/', {
|
||||
preventDefault,
|
||||
});
|
||||
|
||||
|
||||
t.calledWithNoArgs(preventDefault, 'should call preventDefault');
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -417,94 +414,97 @@ 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();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: key: n', (t) => {
|
||||
const findNext = stub();
|
||||
|
||||
|
||||
mockRequire(pathFind, {
|
||||
findNext,
|
||||
});
|
||||
|
||||
|
||||
const vim = reRequire(pathVim);
|
||||
const event = {};
|
||||
|
||||
|
||||
vim('n', event);
|
||||
|
||||
|
||||
stopAll();
|
||||
|
||||
|
||||
t.ok(findNext.calledWith(), 'should call findNext');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: key: N', (t) => {
|
||||
const findPrevious = stub();
|
||||
|
||||
|
||||
mockRequire(pathFind, {
|
||||
findPrevious,
|
||||
});
|
||||
|
||||
|
||||
const vim = reRequire(`${dir}vim`);
|
||||
const event = {};
|
||||
|
||||
|
||||
vim('N', event);
|
||||
|
||||
|
||||
stopAll();
|
||||
|
||||
|
||||
t.ok(findPrevious.calledWith(), 'should call findPrevious');
|
||||
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();
|
||||
});
|
||||
|
|
@ -515,12 +515,12 @@ test('cloudcmd: client: vim: terminal', (t) => {
|
|||
show: stub(),
|
||||
},
|
||||
});
|
||||
|
||||
const event = {
|
||||
};
|
||||
|
||||
const event = {};
|
||||
|
||||
vim('t', event);
|
||||
vim('t', event);
|
||||
|
||||
|
||||
t.calledWithNoArgs(CloudCmd.Terminal.show);
|
||||
t.end();
|
||||
});
|
||||
|
|
@ -531,12 +531,11 @@ test('cloudcmd: client: vim: edit', (t) => {
|
|||
show: stub(),
|
||||
},
|
||||
});
|
||||
|
||||
const event = {
|
||||
};
|
||||
|
||||
const event = {};
|
||||
|
||||
vim('e', event);
|
||||
|
||||
|
||||
t.calledWithNoArgs(CloudCmd.EditFileVim.show);
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ module.exports = (key, operations) => {
|
|||
const prevStore = store();
|
||||
const isVisual = visual();
|
||||
const value = store(prevStore.concat(key));
|
||||
|
||||
const {
|
||||
escape = noop,
|
||||
moveNext = noop,
|
||||
|
|
@ -41,132 +42,129 @@ module.exports = (key, operations) => {
|
|||
terminal = noop,
|
||||
edit = noop,
|
||||
} = operations;
|
||||
|
||||
|
||||
if (key === 'Enter')
|
||||
return end();
|
||||
|
||||
|
||||
if (key === 'Escape') {
|
||||
visual(false);
|
||||
escape();
|
||||
|
||||
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
if (key === 'j' || key === 'w') {
|
||||
const {
|
||||
count,
|
||||
isDelete,
|
||||
isVisual,
|
||||
} = handleDelete(prevStore);
|
||||
|
||||
|
||||
!isNaN(count) && moveNext({
|
||||
count,
|
||||
isVisual,
|
||||
isDelete,
|
||||
});
|
||||
|
||||
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
if (key === 'k' || key === 'b') {
|
||||
const {
|
||||
count,
|
||||
isDelete,
|
||||
isVisual,
|
||||
} = handleDelete(prevStore);
|
||||
|
||||
|
||||
!isNaN(count) && movePrevious({
|
||||
count,
|
||||
isVisual,
|
||||
isDelete,
|
||||
});
|
||||
|
||||
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
if (value === 'gg' || key === '^') {
|
||||
const {
|
||||
isDelete,
|
||||
isVisual,
|
||||
} = handleDelete(prevStore);
|
||||
|
||||
const {isDelete, isVisual} = handleDelete(prevStore);
|
||||
|
||||
movePrevious({
|
||||
count: Infinity,
|
||||
isVisual,
|
||||
isDelete,
|
||||
});
|
||||
|
||||
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
if (value === 'md') {
|
||||
makeDirectory();
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
if (value === 'tt') {
|
||||
terminal();
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
if (value === 'e') {
|
||||
edit();
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
if (value === 'mf') {
|
||||
makeFile();
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
if (key === 'd' && (visual() || prevStore === 'd')) {
|
||||
stopVisual();
|
||||
remove();
|
||||
|
||||
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
if (key === 'G' || key === '$') {
|
||||
moveNext({
|
||||
count: Infinity,
|
||||
isVisual,
|
||||
});
|
||||
|
||||
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
if (key === 'y') {
|
||||
if (!visual())
|
||||
return end();
|
||||
|
||||
|
||||
stopVisual();
|
||||
copy();
|
||||
|
||||
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
if (/^p$/i.test(key)) {
|
||||
paste();
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
if (/^v$/i.test(key)) {
|
||||
visual(!visual());
|
||||
select();
|
||||
|
||||
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
if (key === '/') {
|
||||
find();
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
if (key === 'n') {
|
||||
findNext();
|
||||
return end();
|
||||
}
|
||||
|
||||
|
||||
if (key === 'N') {
|
||||
findPrevious();
|
||||
return end();
|
||||
|
|
@ -175,15 +173,15 @@ module.exports = (key, operations) => {
|
|||
|
||||
function handleDelete(prevStore) {
|
||||
const isDelete = prevStore[0] === 'd';
|
||||
|
||||
|
||||
if (isDelete) {
|
||||
visual(true);
|
||||
prevStore = rmFirst(prevStore);
|
||||
}
|
||||
|
||||
|
||||
const count = getNumber(prevStore);
|
||||
const isVisual = visual();
|
||||
|
||||
|
||||
return {
|
||||
count,
|
||||
isDelete,
|
||||
|
|
@ -194,10 +192,9 @@ function handleDelete(prevStore) {
|
|||
function getNumber(value) {
|
||||
if (!value)
|
||||
return 1;
|
||||
|
||||
|
||||
if (value === 'g')
|
||||
return 1;
|
||||
|
||||
|
||||
return parseInt(value);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const {
|
||||
test,
|
||||
stub,
|
||||
} = require('supertape');
|
||||
const {test, stub} = require('supertape');
|
||||
|
||||
const vim = require('./vim');
|
||||
|
||||
|
|
@ -64,4 +61,3 @@ test('vim: b', (t) => {
|
|||
t.calledWith(movePrevious, [expected], 'should call movePrevious');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue