fix: code block disables continuous input of characters (#12)

This commit is contained in:
Kilu.He
2025-01-10 15:40:46 +08:00
committed by GitHub
parent 4152b46bd2
commit a8ea6c04d2
2 changed files with 18 additions and 11 deletions

View File

@@ -69,7 +69,7 @@ function MermaidChat ({ node }: {
const isDark = useContext(ThemeModeContext)?.isDark;
const [error, setError] = React.useState<string | null>(null);
const updateMermaid = useCallback(async () => {
const updateMermaid = useCallback(async (diagram: string) => {
const sanitizedDiagram = sanitizeDiagram(diagram);
const theme = isDark ? darkTheme : lightTheme;
@@ -91,17 +91,23 @@ function MermaidChat ({ node }: {
// @ts-ignore
setError(e.message);
}
}, [diagram, id, isDark]);
}, [id, isDark]);
const deboucenUpdateMermaid = useMemo(() => {
return debounce(updateMermaid, 1000);
}, [updateMermaid]);
useEffect(() => {
void deboucenUpdateMermaid();
}, [deboucenUpdateMermaid]);
if (!diagram.trim()) {
setError(null);
setInnerHtml('');
return;
}
if (error) {
void deboucenUpdateMermaid(diagram);
}, [deboucenUpdateMermaid, diagram]);
if (error && diagram) {
return (
<div
contentEditable={false}
@@ -121,7 +127,6 @@ function MermaidChat ({ node }: {
display: 'flex',
flexDirection: 'row',
placeContent: 'center',
minHeight: '250px',
}}
contentEditable={false}
ref={ref}

View File

@@ -331,7 +331,6 @@ const rules: Rule[] = [
match: /--/,
format: SpecialSymbol.EM_DASH,
transform: (editor) => {
editor.delete({
unit: 'character',
reverse: true,
@@ -422,6 +421,9 @@ export const applyMarkdown = (editor: YjsEditor, insertText: string): boolean =>
}
} else if (rule.type === 'symbol') {
const block = getBlockEntry(editor)[0];
if (block.type === BlockType.CodeBlock) return false;
const path = selection.anchor.path;
const text = editor.string({
anchor: {