Skip to content

Commit

Permalink
fix(doc): inserting the document overwrote the existing content
Browse files Browse the repository at this point in the history
  • Loading branch information
mayneyao committed Jul 15, 2024
1 parent 2048823 commit 8dae063
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion components/cmdk/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
CommandSeparator,
CommandShortcut,
} from "@/components/ui/command"
import { useLastOpened } from "@/app/[database]/hook"
import { useSpaceAppStore } from "@/app/[database]/store"

import { ActionList } from "./action"
Expand Down Expand Up @@ -67,7 +68,7 @@ export function CommandDialogDemo() {
}, [input, run, space])

const { isAiOpen, setIsAiOpen } = useSpaceAppStore()
const { lastOpenedDatabase } = useAppStore()
const { lastOpenedDatabase } = useLastOpened()

const { createDoc } = useSqlite()
const goto = useCMDKGoto()
Expand Down
10 changes: 6 additions & 4 deletions components/doc/plugins/AIEditorPlugin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const AIEditorPlugin = (props: any) => {

useEffect(() => {
return mergeRegister(() => {
// FIXME: is this only works in dev mode? fuck lexical fuck fuck fuck!!!!!!!!!
editor.registerCommand(
SELECTION_CHANGE_COMMAND,
() => {
Expand Down Expand Up @@ -65,9 +66,10 @@ export const AIEditorPlugin = (props: any) => {

editor.update(() => {
editor.focus()
const paragraphNode = $createParagraphNode()
$convertFromMarkdownString(text, __allTransformers, paragraphNode)
// FIXME: the selection is always null in production mode, append the paragraph node to the end of the root node yet
if (selection) {
const paragraphNode = $createParagraphNode()
$convertFromMarkdownString(text, __allTransformers, paragraphNode)
const newSelection = selection.clone()
let node
try {
Expand All @@ -77,11 +79,11 @@ export const AIEditorPlugin = (props: any) => {
node.insertAfter(paragraphNode)
} else {
const root = $getRoot()
$convertFromMarkdownString(text, __allTransformers, root)
root.append(paragraphNode)
}
} else {
const root = $getRoot()
$convertFromMarkdownString(text, __allTransformers, root)
root.append(paragraphNode)
}
})
}
Expand Down

0 comments on commit 8dae063

Please sign in to comment.