fix: Improve ranking of results in editor menus when filtering using command-score

This commit is contained in:
Tom Moor
2023-04-05 18:37:50 -04:00
parent 9a7ecd7403
commit 99e4b458df
3 changed files with 7 additions and 4 deletions

View File

@@ -1,3 +1,4 @@
import commandScore from "command-score";
import { capitalize } from "lodash";
import { findParentNode } from "prosemirror-utils";
import * as React from "react";
@@ -397,10 +398,9 @@ function SuggestionsMenu<T extends MenuItem>(props: Props<T>) {
return filterExcessSeparators(
filtered.sort((item) => {
return searchInput &&
(item.title || "").toLowerCase().startsWith(searchInput)
? -1
: 1;
return searchInput && item.title
? commandScore(item.title, searchInput)
: 0;
})
);
}, [commands, props]);

View File

@@ -6,6 +6,8 @@ declare module "sequelize-encrypted";
declare module "styled-components-breakpoint";
declare module "command-score";
declare module "*.png" {
const value: any;
export = value;

View File

@@ -83,6 +83,7 @@
"cancan": "3.1.0",
"chalk": "^4.1.0",
"class-validator": "^0.14.0",
"command-score": "^0.1.2",
"compressorjs": "^1.1.1",
"copy-to-clipboard": "^3.3.3",
"core-js": "^3.26.1",