mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(client) improve vim support: Esc - toggle vim support in editors
This commit is contained in:
parent
4e86f7f308
commit
c002fc37c5
5 changed files with 28 additions and 15 deletions
|
|
@ -1,10 +1,9 @@
|
|||
/* global CloudCmd, DOM */
|
||||
|
||||
'use strict';
|
||||
|
||||
/* global CloudCmd, DOM */
|
||||
|
||||
const Info = DOM.CurrentInfo;
|
||||
|
||||
const exec = require('execon');
|
||||
const clipboard = require('@cloudcmd/clipboard');
|
||||
|
||||
const Buffer = require('../dom/buffer');
|
||||
|
|
@ -130,7 +129,11 @@ async function switchKey(event) {
|
|||
isDir,
|
||||
} = Info;
|
||||
|
||||
const {Operation, loadDir} = CloudCmd;
|
||||
const {
|
||||
Operation,
|
||||
loadDir,
|
||||
config,
|
||||
} = CloudCmd;
|
||||
const {keyCode} = event;
|
||||
|
||||
const alt = event.altKey;
|
||||
|
|
@ -209,7 +212,7 @@ async function switchKey(event) {
|
|||
break;
|
||||
|
||||
case KEY.F4:
|
||||
if (shift)
|
||||
if (config('vim'))
|
||||
CloudCmd.EditFileVim.show();
|
||||
else
|
||||
CloudCmd.EditFile.show();
|
||||
|
|
@ -429,7 +432,7 @@ async function switchKey(event) {
|
|||
|
||||
case KEY.M:
|
||||
if (ctrlMeta) {
|
||||
if (shift)
|
||||
if (config('vim'))
|
||||
CloudCmd.EditNamesVim.show();
|
||||
else
|
||||
CloudCmd.EditNames.show();
|
||||
|
|
|
|||
|
|
@ -13,12 +13,19 @@ const {
|
|||
getCloudCmd,
|
||||
} = require('./vim/globals.fixture');
|
||||
|
||||
global.DOM = getDOM();
|
||||
global.CloudCmd = getCloudCmd();
|
||||
const DOM = getDOM();
|
||||
const CloudCmd = getCloudCmd();
|
||||
|
||||
global.DOM = DOM;
|
||||
global.CloudCmd = CloudCmd;
|
||||
|
||||
test('cloudcmd: client: key: enable vim', async (t) => {
|
||||
const vim = stub();
|
||||
const configStub = stub().returns(true);
|
||||
const {CloudCmd} = global;
|
||||
const {config} = CloudCmd;
|
||||
|
||||
CloudCmd.config = configStub;
|
||||
mockRequire('./vim', vim);
|
||||
const {_listener, setBind} = reRequire('.');
|
||||
|
||||
|
|
@ -31,6 +38,7 @@ test('cloudcmd: client: key: enable vim', async (t) => {
|
|||
setBind();
|
||||
await _listener(event);
|
||||
|
||||
CloudCmd.config = config;
|
||||
stopAll();
|
||||
|
||||
t.calledWith(vim, ['Escape', event]);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
module.exports.getDOM = () => {
|
||||
const prompt = Promise.resolve.bind(Promise);
|
||||
const CurrentInfo = {
|
||||
|
|
@ -7,7 +9,6 @@ module.exports.getDOM = () => {
|
|||
files: [],
|
||||
};
|
||||
|
||||
const noop = () => {};
|
||||
const Buffer = {
|
||||
copy: noop,
|
||||
paste: noop,
|
||||
|
|
@ -38,6 +39,9 @@ module.exports.getCloudCmd = () => {
|
|||
Operation: {
|
||||
show,
|
||||
},
|
||||
|
||||
config: noop,
|
||||
_config: noop,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ test('cloudcmd: client: view: initConfig', (t) => {
|
|||
global.CloudCmd = {};
|
||||
global.DOM = {};
|
||||
|
||||
const {_initConfig} = reRequire('./view');
|
||||
const {_initConfig} = reRequire('.');
|
||||
|
||||
const afterClose = () => ++i;
|
||||
const options = {
|
||||
|
|
@ -43,7 +43,7 @@ test('cloudcmd: client: view: initConfig: no options', (t) => {
|
|||
global.CloudCmd = {};
|
||||
global.DOM = {};
|
||||
|
||||
const {_initConfig} = reRequire('./view');
|
||||
const {_initConfig} = reRequire('.');
|
||||
const config = _initConfig();
|
||||
|
||||
global.CloudCmd = CloudCmd;
|
||||
|
|
@ -68,7 +68,7 @@ test('cloudcmd: client: view: html', (t) => {
|
|||
_viewHtml,
|
||||
_createIframe,
|
||||
_Config,
|
||||
} = reRequire('./view');
|
||||
} = reRequire('.');
|
||||
|
||||
const src = '/hello.html';
|
||||
_viewHtml(src);
|
||||
Loading…
Add table
Add a link
Reference in a new issue