mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-18 09:35:20 +02:00
55cafb8891
Co-authored-by: Laurent Cozic <laurent22@users.noreply.github.com>
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
/* eslint-disable import/prefer-default-export */
|
|
|
|
// This contains the CodeMirror instance, which needs to be built into a bundle
|
|
// using `yarn buildInjectedJs`. This bundle is then loaded from
|
|
// NoteEditor.tsx into the webview.
|
|
//
|
|
// In general, since this file is harder to debug due to the intermediate built
|
|
// step, it's better to keep it as light as possible - it should just be a light
|
|
// wrapper to access CodeMirror functionalities. Anything else should be done
|
|
// from NoteEditor.tsx.
|
|
|
|
import { EditorSettings } from '@joplin/editor/types';
|
|
import createEditor from '@joplin/editor/CodeMirror/createEditor';
|
|
import CodeMirrorControl from '@joplin/editor/CodeMirror/CodeMirrorControl';
|
|
import WebViewToRNMessenger from '../../../utils/ipc/WebViewToRNMessenger';
|
|
import { WebViewToEditorApi } from '../types';
|
|
|
|
export const initCodeMirror = (
|
|
parentElement: HTMLElement,
|
|
initialText: string,
|
|
settings: EditorSettings,
|
|
): CodeMirrorControl => {
|
|
const messenger = new WebViewToRNMessenger<CodeMirrorControl, WebViewToEditorApi>('editor', null);
|
|
|
|
const control = createEditor(parentElement, {
|
|
initialText,
|
|
settings,
|
|
|
|
onLogMessage: message => {
|
|
void messenger.remoteApi.logMessage(message);
|
|
},
|
|
onEvent: (event): void => {
|
|
void messenger.remoteApi.onEditorEvent(event);
|
|
},
|
|
});
|
|
|
|
messenger.setLocalInterface(control);
|
|
return control;
|
|
};
|