refactor(select-by-pattern) forEach -> for-of

This commit is contained in:
coderaiser 2019-05-22 11:44:56 +03:00
parent 19239655ed
commit ba72727fba
2 changed files with 34 additions and 39 deletions

View file

@ -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!');
};

View file

@ -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('*', '.*')