fix: mentions and slash commands now work well with multiple editors in one place

This commit is contained in:
Palanikannan1437 2024-03-27 11:28:53 +05:30
parent 48f913fbe6
commit 625205f972
4 changed files with 6 additions and 13 deletions

View File

@ -53,7 +53,7 @@ export const EditorContainer: FC<EditorContainerProps> = (props) => {
onMouseLeave={() => {
hideDragHandle?.();
}}
className={`cursor-text ${editorClassNames}`}
className={`cursor-text ${editorClassNames} ${editor?.isFocused && editor?.isEditable ? "active-editor" : ""}`}
>
{children}
</div>

View File

@ -4,7 +4,6 @@ import { ReactRenderer } from "@tiptap/react";
import { Editor } from "@tiptap/core";
import tippy from "tippy.js";
import { v4 as uuidv4 } from "uuid";
import { MentionList } from "src/ui/mentions/mention-list";
export const Mentions = ({
@ -28,9 +27,6 @@ export const Mentions = ({
let component: ReactRenderer | null = null;
let popup: any | null = null;
const hidePopup = () => {
popup?.[0].hide();
};
return {
onStart: (props: { editor: Editor; clientRect: DOMRect }) => {
if (!props.clientRect) {
@ -44,14 +40,13 @@ export const Mentions = ({
// @ts-expect-error - Tippy types are incorrect
popup = tippy("body", {
getReferenceClientRect: props.clientRect,
appendTo: () => document.body,
appendTo: () => document.querySelector(".active-editor"),
content: component.element,
showOnCreate: true,
interactive: true,
trigger: "manual",
placement: "bottom-start",
});
// document.addEventListener("scroll", hidePopup, true);
},
onUpdate: (props: { editor: Editor; clientRect: DOMRect }) => {
component?.updateProps(props);
@ -87,8 +82,6 @@ export const Mentions = ({
props.editor.storage.mentionsOpen = false;
popup?.[0].destroy();
component?.destroy();
// document.removeEventListener("scroll", hidePopup, true);
},
};
},

View File

@ -35,9 +35,9 @@ export const MentionList = forwardRef((props: MentionListProps, ref) => {
};
});
const filteredSuggestions = mappedSuggestions
.filter((suggestion) => suggestion.title.toLowerCase().startsWith(query.toLowerCase()))
.slice(0, 5);
const filteredSuggestions = mappedSuggestions.filter((suggestion) =>
suggestion.title.toLowerCase().startsWith(query.toLowerCase())
);
setItems(filteredSuggestions);
setIsLoading(false); // End loading

View File

@ -330,7 +330,7 @@ const renderItems = () => {
// @ts-ignore
popup = tippy("body", {
getReferenceClientRect: props.clientRect,
appendTo: () => document.body,
appendTo: () => document.querySelector(".active-editor"),
content: component.element,
showOnCreate: true,
interactive: true,