feature(client) improve vim support: Esc - toggle vim support in editors

This commit is contained in:
coderaiser 2021-01-17 16:07:39 +02:00
parent 4e86f7f308
commit c002fc37c5
5 changed files with 28 additions and 15 deletions

View file

@ -158,7 +158,6 @@ Then, start the server again with `cloudcmd` and reload the page.
| `F3` | view, change directory
| `Shift + F3` | view raw file, change directory
| `F4` | edit
| `Shift + F4` | edit in "vim" mode
| `F5` | copy
| `Alt` + `F5` | pack
| `F6` | rename/move
@ -182,7 +181,6 @@ Then, start the server again with `cloudcmd` and reload the page.
| `Ctrl + D` | clear local storage
| `Ctrl + A` | select all files in a panel
| `Ctrl + M` | [rename selected files](https://github.com/coderaiser/cloudcmd/releases/tag/v12.1.0) in editor
| `Shift + Ctrl + M` | rename selected files in vim mode of editor
| `Ctrl + U` | swap panels
| `Ctrl + F3` | sort by name
| `Ctrl + F5` | sort by date
@ -201,7 +199,7 @@ Then, start the server again with `cloudcmd` and reload the page.
| `Insert` | select current file (and move to next)
| `F9` | context menu
| `~` | console
| `Esc` | toggle vim hot keys
| `Esc` | toggle vim hotkeys (`file manager`, `editor`)
### Vim

View file

@ -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();

View file

@ -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]);

View file

@ -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,
};
};

View file

@ -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);