mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-26 09:24:07 +00:00
feature(vim) add find support with: "/", "n" and "N"
This commit is contained in:
parent
3693f6f799
commit
2edf7f8321
7 changed files with 269 additions and 29 deletions
53
client/key/vim/find.js
Normal file
53
client/key/vim/find.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
'use strict';
|
||||
/* global DOM */
|
||||
|
||||
const fullstore = require('fullstore');
|
||||
const limier = require('limier');
|
||||
const Info = DOM.CurrentInfo;
|
||||
|
||||
const searchStore = fullstore([]);
|
||||
const searchIndex = fullstore(0);
|
||||
|
||||
module.exports.find = (value) => {
|
||||
const names = Info.files.map(DOM.getCurrentName);
|
||||
const result = limier(value, names);
|
||||
|
||||
searchStore(result);
|
||||
searchIndex(0);
|
||||
|
||||
DOM.setCurrentByName(result[0]);
|
||||
};
|
||||
|
||||
module.exports.findNext = () => {
|
||||
const names = searchStore();
|
||||
const index = next(searchIndex(), names.length);
|
||||
|
||||
searchIndex(index);
|
||||
DOM.setCurrentByName(names[searchIndex()]);
|
||||
};
|
||||
|
||||
module.exports.findPrevious = () => {
|
||||
const names = searchStore();
|
||||
const index = previous(searchIndex(), names.length);
|
||||
|
||||
searchIndex(index);
|
||||
DOM.setCurrentByName(names[index]);
|
||||
};
|
||||
|
||||
module.exports._next = next;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -1,12 +1,20 @@
|
|||
'use strict';
|
||||
/* global CloudCmd, DOM */
|
||||
|
||||
const KEY = require('../key');
|
||||
const Info = DOM.CurrentInfo;
|
||||
const KEY = require('./key');
|
||||
const Dialog = DOM.Dialog;
|
||||
|
||||
const fullstore = require('fullstore/legacy');
|
||||
const store = fullstore('');
|
||||
const visual = fullstore(false);
|
||||
const {
|
||||
find,
|
||||
findNext,
|
||||
findPrevious,
|
||||
} = require('./find');
|
||||
|
||||
const TITLE = 'Cloud Commander';
|
||||
|
||||
const stopVisual = () => {
|
||||
visual(false);
|
||||
|
|
@ -104,6 +112,25 @@ module.exports = (key, event) => {
|
|||
|
||||
return end();
|
||||
}
|
||||
|
||||
if (key === '/') {
|
||||
event.preventDefault();
|
||||
|
||||
Dialog.prompt(TITLE, 'Find', '', {cancel: false})
|
||||
.then(find);
|
||||
|
||||
return end();
|
||||
}
|
||||
|
||||
if (key === 'n') {
|
||||
findNext();
|
||||
return end();
|
||||
}
|
||||
|
||||
if (key === 'N') {
|
||||
findPrevious();
|
||||
return end();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.selectFile = selectFile;
|
||||
Loading…
Add table
Add a link
Reference in a new issue