1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-18 09:35:20 +02:00
joplin/packages/editor/CodeMirror/utils/handleLinkEditRequests.ts

26 lines
568 B
TypeScript

import { EditorState, StateEffect } from '@codemirror/state';
import { EditorView } from '@codemirror/view';
export const showLinkEditorEffect = StateEffect.define<void>();
export const showLinkEditor = (view: EditorView) => {
view.dispatch({
effects: [
showLinkEditorEffect.of(),
],
});
return true;
};
const handleLinkEditRequests = (onShowEditor: ()=> void) => [
EditorState.transactionExtender.of(tr => {
if (tr.effects.some(e => e.is(showLinkEditorEffect))) {
onShowEditor();
}
return null;
}),
];
export default handleLinkEditRequests;