mirror of https://github.com/laurent22/joplin.git
parent
2f3d207096
commit
aff1bf501f
|
@ -389,6 +389,7 @@ const CodeMirror = (props: NoteBodyEditorProps, ref: ForwardedRef<NoteBodyEditor
|
|||
pluginStates={props.plugins}
|
||||
onEvent={onEditorEvent}
|
||||
onLogMessage={logDebug}
|
||||
onEditorPaste={onEditorPaste}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -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<CodeMirrorControl>) => {
|
||||
|
@ -29,6 +31,23 @@ const Editor = (props: Props, ref: ForwardedRef<CodeMirrorControl>) => {
|
|||
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]);
|
||||
|
|
|
@ -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),
|
||||
}),
|
||||
|
|
Loading…
Reference in New Issue