diff --git a/src/plugins/diff-source/DiffViewer.tsx b/src/plugins/diff-source/DiffViewer.tsx index ccc98e48..f1c3a7c2 100644 --- a/src/plugins/diff-source/DiffViewer.tsx +++ b/src/plugins/diff-source/DiffViewer.tsx @@ -24,6 +24,7 @@ interface CmMergeViewProps { const CmMergeView: React.FC = ({ oldMarkdown, newMarkdown, onUpdate }) => { const cmMergeViewRef = React.useRef(null) const [cmExtensions] = diffSourcePluginHooks.useEmitterValues('cmExtensions') + const triggerOnBlur = corePluginHooks.usePublisher('onBlur') const ref = React.useCallback( (el: HTMLDivElement | null) => { @@ -51,6 +52,12 @@ const CmMergeView: React.FC = ({ oldMarkdown, newMarkdown, onU EditorView.updateListener.of(({ state }) => { const md = state.doc.toString() onUpdate(md) + }), + EditorView.focusChangeEffect.of((_, focused) => { + if (!focused) { + triggerOnBlur(new FocusEvent('blur')) + } + return null }) ] } @@ -60,7 +67,7 @@ const CmMergeView: React.FC = ({ oldMarkdown, newMarkdown, onU cmMergeViewRef.current = null } }, - [newMarkdown, oldMarkdown, onUpdate, cmExtensions] + [newMarkdown, oldMarkdown, onUpdate, cmExtensions, triggerOnBlur] ) return
diff --git a/src/plugins/diff-source/SourceEditor.tsx b/src/plugins/diff-source/SourceEditor.tsx index e0186b12..8b408797 100644 --- a/src/plugins/diff-source/SourceEditor.tsx +++ b/src/plugins/diff-source/SourceEditor.tsx @@ -19,6 +19,7 @@ export const SourceEditor = () => { const [markdown, readOnly] = corePluginHooks.useEmitterValues('markdown', 'readOnly') const [cmExtensions] = diffSourcePluginHooks.useEmitterValues('cmExtensions') const updateMarkdown = diffSourcePluginHooks.usePublisher('markdownSourceEditorValue') + const triggerOnBlur = corePluginHooks.usePublisher('onBlur') const editorViewRef = React.useRef(null) const ref = React.useCallback( @@ -30,6 +31,12 @@ export const SourceEditor = () => { ...COMMON_STATE_CONFIG_EXTENSIONS, EditorView.updateListener.of(({ state }) => { updateMarkdown(state.doc.toString()) + }), + EditorView.focusChangeEffect.of((_, focused) => { + if (!focused) { + triggerOnBlur(new FocusEvent('blur')) + } + return null }) ] if (readOnly) { @@ -45,7 +52,7 @@ export const SourceEditor = () => { editorViewRef.current = null } }, - [markdown, readOnly, updateMarkdown, cmExtensions] + [markdown, readOnly, updateMarkdown, cmExtensions, triggerOnBlur] ) return