diff --git a/app/editor/components/MentionMenu.tsx b/app/editor/components/MentionMenu.tsx
index 75beb44a20..80e3551c56 100644
--- a/app/editor/components/MentionMenu.tsx
+++ b/app/editor/components/MentionMenu.tsx
@@ -13,6 +13,7 @@ import Document from "~/models/Document";
import User from "~/models/User";
import { Avatar, AvatarSize } from "~/components/Avatar";
import Flex from "~/components/Flex";
+import { DocumentSection, UserSection } from "~/actions/sections";
import useRequest from "~/hooks/useRequest";
import useStores from "~/hooks/useStores";
import { client } from "~/utils/ApiClient";
@@ -84,6 +85,7 @@ function MentionMenu({ search, isActive, ...rest }: Props) {
),
title: user.name,
+ section: UserSection,
appendSpace: true,
attrs: {
id: v4(),
@@ -102,6 +104,8 @@ function MentionMenu({ search, isActive, ...rest }: Props) {
),
title: doc.title,
+ subtitle: doc.collection?.name,
+ section: DocumentSection,
appendSpace: true,
attrs: {
id: v4(),
@@ -166,6 +170,7 @@ function MentionMenu({ search, isActive, ...rest }: Props) {
diff --git a/app/editor/components/SuggestionsMenu.tsx b/app/editor/components/SuggestionsMenu.tsx
index dc8cd74df4..2d30010285 100644
--- a/app/editor/components/SuggestionsMenu.tsx
+++ b/app/editor/components/SuggestionsMenu.tsx
@@ -1,7 +1,8 @@
import commandScore from "command-score";
import capitalize from "lodash/capitalize";
+import orderBy from "lodash/orderBy";
import * as React from "react";
-import { Trans } from "react-i18next";
+import { Trans, useTranslation } from "react-i18next";
import { VisuallyHidden } from "reakit/VisuallyHidden";
import { toast } from "sonner";
import styled from "styled-components";
@@ -13,6 +14,7 @@ import { MenuItem } from "@shared/editor/types";
import { depths, s } from "@shared/styles";
import { getEventFiles } from "@shared/utils/files";
import { AttachmentValidation } from "@shared/validations";
+import Header from "~/components/ContextMenu/Header";
import { Portal } from "~/components/Portal";
import Scrollable from "~/components/Scrollable";
import useDictionary from "~/hooks/useDictionary";
@@ -80,6 +82,7 @@ export type Props = {
function SuggestionsMenu(props: Props) {
const { view, commands } = useEditor();
const dictionary = useDictionary();
+ const { t } = useTranslation();
const hasActivated = React.useRef(false);
const pointerRef = React.useRef<{ clientX: number; clientY: number }>({
clientX: 0,
@@ -445,18 +448,20 @@ function SuggestionsMenu(props: Props) {
});
return filterExcessSeparators(
- filtered
- .map((item) => ({
+ orderBy(
+ filtered.map((item) => ({
item,
+ section: "section" in item ? item.section?.({ t }) : "default",
score:
searchInput && item.title
? commandScore(item.title, searchInput)
: 0,
- }))
- .sort((a, b) => b.score - a.score)
- .map(({ item }) => item)
+ })),
+ ["section", "score"],
+ ["asc", "desc"]
+ ).map(({ item }) => item)
);
- }, [commands, props]);
+ }, [t, commands, props]);
React.useEffect(() => {
const handleMouseDown = (event: MouseEvent) => {
@@ -555,6 +560,7 @@ function SuggestionsMenu(props: Props) {
const { isActive, uploadFile } = props;
const items = filtered;
+ let previousHeading: string | undefined;
return (
@@ -614,18 +620,29 @@ function SuggestionsMenu(props: Props) {
}
};
- return (
-
- {props.renderMenuItem(item as any, index, {
- selected: index === selectedIndex,
- onClick: () => handleClickItem(item),
- })}
-
+ const currentHeading =
+ "section" in item ? item.section?.({ t }) : undefined;
+
+ const response = (
+ <>
+ {currentHeading !== previousHeading && (
+
+ )}
+
+ {props.renderMenuItem(item as any, index, {
+ selected: index === selectedIndex,
+ onClick: () => handleClickItem(item),
+ })}
+
+ >
);
+
+ previousHeading = currentHeading;
+ return response;
})}
{items.length === 0 && (
diff --git a/app/editor/components/SuggestionsMenuItem.tsx b/app/editor/components/SuggestionsMenuItem.tsx
index a64d4a8df6..23b32ee854 100644
--- a/app/editor/components/SuggestionsMenuItem.tsx
+++ b/app/editor/components/SuggestionsMenuItem.tsx
@@ -56,7 +56,7 @@ function SuggestionsMenuItem({
icon={icon}
>
{title}
- {subtitle && {subtitle}}
+ {subtitle && · {subtitle}}
{shortcut && {shortcut}}
);
diff --git a/shared/editor/types/index.ts b/shared/editor/types/index.ts
index 17b3623524..07ea6fec73 100644
--- a/shared/editor/types/index.ts
+++ b/shared/editor/types/index.ts
@@ -1,3 +1,4 @@
+import { TFunction } from "i18next";
import { Node as ProsemirrorNode } from "prosemirror-model";
import { EditorState } from "prosemirror-state";
import { EditorView } from "prosemirror-view";
@@ -15,10 +16,13 @@ export enum TableLayout {
fullWidth = "full-width",
}
+type Section = ({ t }: { t: TFunction }) => string;
+
export type MenuItem = {
icon?: React.ReactElement;
name?: string;
title?: string;
+ section?: Section;
subtitle?: string;
shortcut?: string;
keywords?: string;