diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/CodeMirror.tsx b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/CodeMirror.tsx index 06f75b52b9..8009a725d5 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/CodeMirror.tsx +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/CodeMirror.tsx @@ -389,6 +389,7 @@ const CodeMirror = (props: NoteBodyEditorProps, ref: ForwardedRef ); diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/Editor.tsx b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/Editor.tsx index 595248a545..f00d240ac8 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/Editor.tsx +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/v6/Editor.tsx @@ -13,6 +13,8 @@ import setupVim from '../utils/setupVim'; interface Props extends EditorProps { style: React.CSSProperties; pluginStates: PluginStates; + + onEditorPaste: ()=> void; } const Editor = (props: Props, ref: ForwardedRef) => { @@ -29,6 +31,23 @@ const Editor = (props: Props, ref: ForwardedRef) => { onLogMessageRef.current = props.onLogMessage; }, [props.onEvent, props.onLogMessage]); + useEffect(() => { + if (!editor) { + return () => {}; + } + + const pasteEventHandler = (_editor: any, event: Event) => { + event.preventDefault(); + props.onEditorPaste(); + }; + + editor.on('paste', pasteEventHandler); + + return () => { + editor.off('paste', pasteEventHandler); + }; + }, [editor, props.onEditorPaste]); + useImperativeHandle(ref, () => { return editor; }, [editor]); diff --git a/packages/editor/CodeMirror/CodeMirror5Emulation/CodeMirror5Emulation.ts b/packages/editor/CodeMirror/CodeMirror5Emulation/CodeMirror5Emulation.ts index c130eab2b5..3bb122fa82 100644 --- a/packages/editor/CodeMirror/CodeMirror5Emulation/CodeMirror5Emulation.ts +++ b/packages/editor/CodeMirror/CodeMirror5Emulation/CodeMirror5Emulation.ts @@ -72,6 +72,7 @@ export default class CodeMirror5Emulation extends BaseCodeMirror5Emulation { EditorView.domEventHandlers({ scroll: () => CodeMirror5Emulation.signal(this, 'scroll'), focus: () => CodeMirror5Emulation.signal(this, 'focus'), + paste: event => CodeMirror5Emulation.signal(this, 'paste', event), blur: () => CodeMirror5Emulation.signal(this, 'blur'), mousedown: event => CodeMirror5Emulation.signal(this, 'mousedown', event), }),