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