fix: Improve ranking of results in editor menus when filtering using command-score
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import commandScore from "command-score";
|
||||||
import { capitalize } from "lodash";
|
import { capitalize } from "lodash";
|
||||||
import { findParentNode } from "prosemirror-utils";
|
import { findParentNode } from "prosemirror-utils";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
@@ -397,10 +398,9 @@ function SuggestionsMenu<T extends MenuItem>(props: Props<T>) {
|
|||||||
|
|
||||||
return filterExcessSeparators(
|
return filterExcessSeparators(
|
||||||
filtered.sort((item) => {
|
filtered.sort((item) => {
|
||||||
return searchInput &&
|
return searchInput && item.title
|
||||||
(item.title || "").toLowerCase().startsWith(searchInput)
|
? commandScore(item.title, searchInput)
|
||||||
? -1
|
: 0;
|
||||||
: 1;
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}, [commands, props]);
|
}, [commands, props]);
|
||||||
|
|||||||
2
app/typings/index.d.ts
vendored
2
app/typings/index.d.ts
vendored
@@ -6,6 +6,8 @@ declare module "sequelize-encrypted";
|
|||||||
|
|
||||||
declare module "styled-components-breakpoint";
|
declare module "styled-components-breakpoint";
|
||||||
|
|
||||||
|
declare module "command-score";
|
||||||
|
|
||||||
declare module "*.png" {
|
declare module "*.png" {
|
||||||
const value: any;
|
const value: any;
|
||||||
export = value;
|
export = value;
|
||||||
|
|||||||
@@ -83,6 +83,7 @@
|
|||||||
"cancan": "3.1.0",
|
"cancan": "3.1.0",
|
||||||
"chalk": "^4.1.0",
|
"chalk": "^4.1.0",
|
||||||
"class-validator": "^0.14.0",
|
"class-validator": "^0.14.0",
|
||||||
|
"command-score": "^0.1.2",
|
||||||
"compressorjs": "^1.1.1",
|
"compressorjs": "^1.1.1",
|
||||||
"copy-to-clipboard": "^3.3.3",
|
"copy-to-clipboard": "^3.3.3",
|
||||||
"core-js": "^3.26.1",
|
"core-js": "^3.26.1",
|
||||||
|
|||||||
Reference in New Issue
Block a user