Skip to content

Commit

Permalink
fix: code node clean
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Feb 2, 2024
1 parent 619f0ea commit 9a2535d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/components/ui/code-editor/CodeEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { forwardRef, useEffect, useState } from 'react'

import { stopPropagation } from '~/lib/dom'
import { clsxm } from '~/lib/helper'

import { BaseCodeHighlighter } from '../code-highlighter'
Expand Down Expand Up @@ -33,6 +34,8 @@ export const CodeEditor = forwardRef<
contentEditable={false}
>
<textarea
onKeyDown={stopPropagation}
onKeyUp={stopPropagation}
contentEditable={false}
ref={ref}
className="absolute h-full w-full resize-none overflow-hidden bg-transparent p-0 text-transparent caret-accent"
Expand Down
15 changes: 12 additions & 3 deletions src/components/ui/editor/Milkdown/plugins/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ const CodeBlock = () => {

switch (language) {
case 'excalidraw': {
return <ExcalidrawBoard content={content || '{}'} />
return (
<div contentEditable={false}>
<ExcalidrawBoard content={content || '{}'} />
</div>
)
}
}

return (
<div className="my-4">
<div className="my-4" contentEditable={false}>
<NormalCodeBlock content={content || ''} language={language} />
</div>
)
Expand Down Expand Up @@ -62,9 +66,14 @@ const NormalCodeBlock: FC<{
const node = nodeCtx.node

const pos = nodeCtx.getPos()
const tr = view.state.tr
if (!pos) return
if (!code) {
// remove node

const tr = view.state.tr
view.dispatch(view.state.tr.delete(pos, pos + node.nodeSize))
return
}

const nextNode = ctx!.get(schemaCtx).text(code)

Expand Down

0 comments on commit 9a2535d

Please sign in to comment.