mirror of
https://github.com/docmost/docmost.git
synced 2026-08-31 02:46:27 +08:00
fix suggestion menu exit bug
This commit is contained in:
@@ -164,7 +164,7 @@ const MentionList = forwardRef<any, MentionListProps>((props, ref) => {
|
|||||||
|
|
||||||
const enterHandler = () => {
|
const enterHandler = () => {
|
||||||
if (!renderItems.length) return;
|
if (!renderItems.length) return;
|
||||||
if (renderItems[selectedIndex].entityType !== "header") {
|
if (renderItems[selectedIndex]?.entityType !== "header") {
|
||||||
selectItem(selectedIndex);
|
selectItem(selectedIndex);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -204,7 +204,7 @@ const MentionList = forwardRef<any, MentionListProps>((props, ref) => {
|
|||||||
parentPageId: page.id || null,
|
parentPageId: page.id || null,
|
||||||
title: title
|
title: title
|
||||||
};
|
};
|
||||||
|
|
||||||
let createdPage: IPage;
|
let createdPage: IPage;
|
||||||
try {
|
try {
|
||||||
createdPage = await createPageMutation.mutateAsync(payload);
|
createdPage = await createPageMutation.mutateAsync(payload);
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ const mentionRenderItems = () => {
|
|||||||
{
|
{
|
||||||
placement: "bottom-start",
|
placement: "bottom-start",
|
||||||
middleware: [offset(0), flip(), shift()],
|
middleware: [offset(0), flip(), shift()],
|
||||||
}
|
},
|
||||||
).then(({ x, y }) => {
|
).then(({ x, y }) => {
|
||||||
Object.assign(element.style, {
|
Object.assign(element.style, {
|
||||||
left: `${x}px`,
|
left: `${x}px`,
|
||||||
@@ -86,7 +86,7 @@ const mentionRenderItems = () => {
|
|||||||
zIndex: "9999",
|
zIndex: "9999",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
onUpdate: (props: {
|
onUpdate: (props: {
|
||||||
@@ -115,23 +115,30 @@ const mentionRenderItems = () => {
|
|||||||
|
|
||||||
// destroy component if space is greater 3 without a match
|
// destroy component if space is greater 3 without a match
|
||||||
if (
|
if (
|
||||||
whitespaceCount > 3 &&
|
whitespaceCount > 4 &&
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
props.editor.storage.mentionItems.length === 0
|
props.editor.storage.mentionItems.length === 1
|
||||||
) {
|
) {
|
||||||
destroy();
|
destroy();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// fallback exit
|
||||||
|
if (whitespaceCount > 7) {
|
||||||
|
destroy();
|
||||||
|
return;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onKeyDown: (props: { event: KeyboardEvent }) => {
|
onKeyDown: (props: { event: KeyboardEvent }) => {
|
||||||
if (props.event.key)
|
if (props.event.key === "Escape") {
|
||||||
if (
|
destroy();
|
||||||
props.event.key === "Escape" ||
|
return true;
|
||||||
(props.event.key === "Enter" && !component)
|
}
|
||||||
) {
|
|
||||||
destroy();
|
if (props.event.key === "Enter" && !component) {
|
||||||
return false;
|
destroy();
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return (component?.ref as any)?.onKeyDown(props);
|
return (component?.ref as any)?.onKeyDown(props);
|
||||||
},
|
},
|
||||||
onExit: () => {
|
onExit: () => {
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ import i18n from "@/i18n.ts";
|
|||||||
import { MarkdownClipboard } from "@/features/editor/extensions/markdown-clipboard.ts";
|
import { MarkdownClipboard } from "@/features/editor/extensions/markdown-clipboard.ts";
|
||||||
import EmojiCommand from "./emoji-command";
|
import EmojiCommand from "./emoji-command";
|
||||||
import { countWords } from "alfaaz";
|
import { countWords } from "alfaaz";
|
||||||
|
import { PluginKey } from "@tiptap/pm/state";
|
||||||
|
|
||||||
const lowlight = createLowlight(common);
|
const lowlight = createLowlight(common);
|
||||||
lowlight.register("mermaid", plaintext);
|
lowlight.register("mermaid", plaintext);
|
||||||
@@ -243,12 +244,12 @@ export const mainExtensions = [
|
|||||||
"Mod-f": () => {
|
"Mod-f": () => {
|
||||||
const event = new CustomEvent("openFindDialogFromEditor", {});
|
const event = new CustomEvent("openFindDialogFromEditor", {});
|
||||||
document.dispatchEvent(event);
|
document.dispatchEvent(event);
|
||||||
return true;
|
return false;
|
||||||
},
|
},
|
||||||
Escape: () => {
|
Escape: () => {
|
||||||
const event = new CustomEvent("closeFindDialogFromEditor", {});
|
const event = new CustomEvent("closeFindDialogFromEditor", {});
|
||||||
document.dispatchEvent(event);
|
document.dispatchEvent(event);
|
||||||
return true;
|
return false;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ export default function PageHeaderMenu({ readOnly }: PageHeaderMenuProps) {
|
|||||||
const event = new CustomEvent("openFindDialogFromEditor", {});
|
const event = new CustomEvent("openFindDialogFromEditor", {});
|
||||||
document.dispatchEvent(event);
|
document.dispatchEvent(event);
|
||||||
},
|
},
|
||||||
|
{ preventDefault: false },
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"Escape",
|
"Escape",
|
||||||
@@ -60,6 +61,7 @@ export default function PageHeaderMenu({ readOnly }: PageHeaderMenuProps) {
|
|||||||
const event = new CustomEvent("closeFindDialogFromEditor", {});
|
const event = new CustomEvent("closeFindDialogFromEditor", {});
|
||||||
document.dispatchEvent(event);
|
document.dispatchEvent(event);
|
||||||
},
|
},
|
||||||
|
{ preventDefault: false },
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
[],
|
[],
|
||||||
@@ -280,7 +282,9 @@ function ConnectionWarning() {
|
|||||||
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const isDisconnected = ["disconnected", "connecting"].includes(yjsConnectionStatus);
|
const isDisconnected = ["disconnected", "connecting"].includes(
|
||||||
|
yjsConnectionStatus,
|
||||||
|
);
|
||||||
|
|
||||||
if (isDisconnected) {
|
if (isDisconnected) {
|
||||||
if (!timeoutRef.current) {
|
if (!timeoutRef.current) {
|
||||||
|
|||||||
Reference in New Issue
Block a user