Skip to content

Commit

Permalink
♻️ 优化搜索内容排序,修复setSubInput 无法触发 inputChange bug
Browse files Browse the repository at this point in the history
  • Loading branch information
muwoo committed Nov 13, 2023
1 parent 1656418 commit 6c096fc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rubick",
"version": "4.1.5",
"version": "4.1.6",
"author": "muwoo <[email protected]>",
"private": true,
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/main/common/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class API extends DBInstance {
value: data.text,
})})`
);
this.sendSubInputChangeEvent({ data });
}

public getPath({ data }) {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/plugins-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const createPluginManager = (): any => {
if (isPin) {
pin.forEach((p, index) => {
if (p.name === plugin.name) {
pin.splice(index, 1);
plugin = pin.splice(index, 1)[0];
}
});
pin.unshift(plugin);
Expand Down
15 changes: 13 additions & 2 deletions src/renderer/plugins-manager/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ const optionsManager = ({
options[0].click();
});

const getIndex = (cmd, value) => {
let index = 0;
if (PinyinMatch.match(cmd.label || cmd, value)) {
index += 1;
}
if (cmd.label) {
index -= 1;
}
return index;
};

const getOptionsFromSearchValue = (value, strict = false) => {
const localPlugins = getGlobal('LOCAL_PLUGINS').getLocalPlugins();
let options: any = [];
Expand All @@ -61,7 +72,7 @@ const optionsManager = ({
desc: fe.explain,
type: plugin.pluginType,
match: PinyinMatch.match(cmd.label || cmd, value),
zIndex: cmd.label ? 0 : 1, // 排序权重
zIndex: getIndex(cmd, value), // 排序权重
click: () => {
pluginClickEvent({
plugin,
Expand Down Expand Up @@ -117,7 +128,7 @@ const optionsManager = ({
.map((plugin) => {
const option = {
...plugin,
zIndex: 1,
zIndex: 0,
click: () => {
openPlugin(plugin, option);
},
Expand Down

0 comments on commit 6c096fc

Please sign in to comment.