bugfix: 修复中文搜索bug

This commit is contained in:
muwoo
2021-07-28 10:36:25 +08:00
parent fbad714b98
commit 5c3f5a76ba
4 changed files with 309 additions and 65 deletions

View File

@@ -229,32 +229,24 @@ APP_FINDER_PATH.forEach((searchPath, index) => {
icon: img.toDataURL(),
desc: path.join(searchPath, appName),
type: 'app',
action: `open ${path.join(searchPath, appName).replace(' ', '\\ ')}`
action: `open ${path.join(searchPath, appName).replace(' ', '\\ ')}`,
keyWords: [appSubStr]
};
if (appZhName && isZhRegex.test(appZhName)) {
const pinyinArr = pinyin(appZhName, { style: pinyin.STYLE_NORMAL });
// pinyinArr = [['pin'], ['yin']]
const firstLetterArr = pinyinArr.map((str) => str[0][0]);
fileOptions.keyWords.push(appZhName);
fileOptions.keyWords.push(pinyinArr.join(''));
fileOptions.keyWords.push(firstLetterArr.join(''));
}
fileLists.push({
...fileOptions,
name: appSubStr,
keyWord: appSubStr
names: JSON.parse(JSON.stringify(fileOptions.keyWords)),
});
if (appZhName && isZhRegex.test(appZhName)) {
let cmds = [];
const pinyinArr = pinyin(appZhName, { style: pinyin.STYLE_NORMAL });
// pinyinArr = [['pin'], ['yin']]
const firstLetterArr = pinyinArr.map((str) => str[0][0]);
cmds.push(appZhName);
cmds.push(pinyinArr.join(''));
cmds.push(firstLetterArr.join(''));
cmds.forEach((cmd) => {
fileLists.push({
...fileOptions,
name: appZhName,
keyWord: cmd
});
});
}
} catch (e) {}
}
}

View File

@@ -214,7 +214,16 @@ const actions = {
.filter((plugin) => {
if (!descMap.get(plugin)) {
descMap.set(plugin, true);
return plugin.keyWord.toLocaleUpperCase().indexOf(value.toLocaleUpperCase()) >= 0;
let has = false;
plugin.keyWords.some(keyWord => {
if (keyWord.toLocaleUpperCase().indexOf(value.toLocaleUpperCase()) >= 0) {
has = keyWord;
plugin.name = keyWord;
return true;
}
return false;
});
return has;
} else {
return false;
}