From 13cd21bce62719aac1ff40d4e7f923ed2ce6233e Mon Sep 17 00:00:00 2001 From: Xuezhou Dai Date: Sun, 16 Apr 2023 04:30:25 +0800 Subject: [PATCH] fix: firefox cursor issue (#348) --- src/pages/dashboard/[subdomain]/editor.tsx | 25 ++++++---------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/pages/dashboard/[subdomain]/editor.tsx b/src/pages/dashboard/[subdomain]/editor.tsx index 27c54b54..59905b7b 100644 --- a/src/pages/dashboard/[subdomain]/editor.tsx +++ b/src/pages/dashboard/[subdomain]/editor.tsx @@ -29,7 +29,7 @@ import { nanoid } from "nanoid" import { useQueryClient } from "@tanstack/react-query" import { PageContent } from "~/components/common/PageContent" import type { Root } from "hast" -import type { EditorView, ViewUpdate } from "@codemirror/view" +import type { EditorView } from "@codemirror/view" import { Editor } from "~/components/ui/Editor" import { renderPageContent } from "~/markdown" import { Button } from "~/components/ui/Button" @@ -124,6 +124,7 @@ export default function SubdomainEditor() { tags: "", content: "", }) + const [initialContent, setInitialContent] = useState("") const [defaultSlug, setDefaultSlug] = useState("") type Values = typeof values @@ -317,7 +318,7 @@ export default function SubdomainEditor() { useEffect(() => { if (!page.data || !draftKey) return - + setInitialContent(page.data.body?.content || "") setValues({ title: page.data.title || "", publishedAt: page.data.date_published, @@ -362,23 +363,9 @@ export default function SubdomainEditor() { [setView], ) - const isComposing = useRef(false) - const bufferedContent = useRef("") const onChange = useCallback( - (value: string, viewUpdate?: ViewUpdate) => { - if (!view?.composing) { - isComposing.current = false - updateValue("content", value) - } else { - if (isComposing.current && viewUpdate) { - bufferedContent.current = value - return - } - isComposing.current = true - requestAnimationFrame(() => { - onChange(bufferedContent.current) - }) - } + (value: string) => { + updateValue("content", value) }, [updateValue], ) @@ -677,7 +664,7 @@ export default function SubdomainEditor() { ) : ( <>