diff --git a/app/editor/components/SuggestionsMenu.tsx b/app/editor/components/SuggestionsMenu.tsx index 7792bbed3..4b15f2969 100644 --- a/app/editor/components/SuggestionsMenu.tsx +++ b/app/editor/components/SuggestionsMenu.tsx @@ -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(props: Props) { 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]); diff --git a/app/typings/index.d.ts b/app/typings/index.d.ts index 5ef0ad108..ebd29ff0c 100644 --- a/app/typings/index.d.ts +++ b/app/typings/index.d.ts @@ -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; diff --git a/package.json b/package.json index 739cf5d64..68d7a845d 100644 --- a/package.json +++ b/package.json @@ -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",