mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
refactor(select-by-pattern) forEach -> for-of
This commit is contained in:
parent
19239655ed
commit
ba72727fba
2 changed files with 34 additions and 39 deletions
|
|
@ -1,51 +1,48 @@
|
|||
'use strict';
|
||||
|
||||
/* global DOM */
|
||||
|
||||
let SelectType = '*.*';
|
||||
|
||||
const {getRegExp} = require('../../common/util');
|
||||
const {
|
||||
alert,
|
||||
prompt,
|
||||
} = require('./dialog');
|
||||
|
||||
module.exports = (msg, files) => {
|
||||
const allMsg = `Specify file type for ${msg} selection`;
|
||||
const cancel = false;
|
||||
const {Dialog} = DOM;
|
||||
const {DOM} = require('.');
|
||||
|
||||
module.exports = async (msg, files) => {
|
||||
if (!files)
|
||||
return;
|
||||
|
||||
Dialog.prompt(allMsg, SelectType, {cancel}).then((type) => {
|
||||
SelectType = type;
|
||||
const allMsg = `Specify file type for ${msg} selection`;
|
||||
|
||||
const type = await prompt(allMsg, SelectType);
|
||||
/* eslint require-atomic-updates: 0 */
|
||||
SelectType = type;
|
||||
|
||||
const regExp = getRegExp(type);
|
||||
|
||||
let matches = 0;
|
||||
|
||||
for (const current of files) {
|
||||
const name = DOM.getCurrentName(current);
|
||||
|
||||
const regExp = getRegExp(type);
|
||||
if (name === '..' || !regExp.test(name))
|
||||
continue;
|
||||
|
||||
if (!files)
|
||||
return;
|
||||
++matches;
|
||||
|
||||
let matches = 0;
|
||||
let isSelected = DOM.isSelected(current);
|
||||
const shouldSel = msg === 'expand';
|
||||
|
||||
files.forEach((current) => {
|
||||
const name = DOM.getCurrentName(current);
|
||||
|
||||
if (name === '..')
|
||||
return;
|
||||
|
||||
const isMatch = regExp.test(name);
|
||||
|
||||
if (!isMatch)
|
||||
return;
|
||||
|
||||
++matches;
|
||||
|
||||
let isSelected = DOM.isSelected(current);
|
||||
const shouldSel = msg === 'expand';
|
||||
|
||||
if (shouldSel)
|
||||
isSelected = !isSelected;
|
||||
|
||||
if (isSelected)
|
||||
DOM.toggleSelectedFile(current);
|
||||
});
|
||||
if (shouldSel)
|
||||
isSelected = !isSelected;
|
||||
|
||||
if (!matches)
|
||||
Dialog.alert('Select Files', 'No matches found!');
|
||||
});
|
||||
if (isSelected)
|
||||
DOM.toggleSelectedFile(current);
|
||||
}
|
||||
|
||||
if (!matches)
|
||||
alert('No matches found!');
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ module.exports.escapeRegExp = (str) => {
|
|||
* get regexp from wild card
|
||||
*/
|
||||
module.exports.getRegExp = (wildcard) => {
|
||||
wildcard = wildcard || '*';
|
||||
|
||||
const escaped = '^' + wildcard // search from start of line
|
||||
.replace('.', '\\.')
|
||||
.replace('*', '.*')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue