2021-07-13 20:13:13 +02:00
|
|
|
/* eslint-disable import/prefer-default-export */
|
|
|
|
|
|
|
|
// This contains the CodeMirror instance, which needs to be built into a bundle
|
2024-01-26 22:19:28 +02:00
|
|
|
// using `yarn buildInjectedJs`. This bundle is then loaded from
|
2021-07-13 20:13:13 +02:00
|
|
|
// 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 shoud just be a light
|
|
|
|
// wrapper to access CodeMirror functionalities. Anything else should be done
|
|
|
|
// from NoteEditor.tsx.
|
|
|
|
|
2023-09-21 10:12:40 +02:00
|
|
|
import { EditorSettings } from '@joplin/editor/types';
|
|
|
|
import createEditor from '@joplin/editor/CodeMirror/createEditor';
|
2022-08-08 17:00:14 +02:00
|
|
|
import { logMessage, postMessage } from './webviewLogger';
|
2023-09-21 10:12:40 +02:00
|
|
|
import CodeMirrorControl from '@joplin/editor/CodeMirror/CodeMirrorControl';
|
2022-12-08 01:19:55 +02:00
|
|
|
|
2022-08-08 17:00:14 +02:00
|
|
|
export function initCodeMirror(
|
2023-09-21 10:12:40 +02:00
|
|
|
parentElement: HTMLElement, initialText: string, settings: EditorSettings,
|
|
|
|
): CodeMirrorControl {
|
|
|
|
return createEditor(parentElement, {
|
|
|
|
initialText,
|
|
|
|
settings,
|
|
|
|
|
|
|
|
onLogMessage: message => {
|
|
|
|
logMessage(message);
|
2022-06-26 19:21:38 +02:00
|
|
|
},
|
2023-09-21 10:12:40 +02:00
|
|
|
onEvent: (event): void => {
|
|
|
|
postMessage('onEditorEvent', event);
|
2022-04-11 12:56:45 +02:00
|
|
|
},
|
2023-09-21 10:12:40 +02:00
|
|
|
});
|
2021-07-13 20:13:13 +02:00
|
|
|
}
|
2022-08-08 17:00:14 +02:00
|
|
|
|