1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-08-10 22:11:50 +02:00

Mobile: Fixes #12891: Fix error logged when opening the Markdown editor (#12892)

This commit is contained in:
Henry Heino
2025-08-06 02:23:07 -07:00
committed by GitHub
parent 4e685ec687
commit 788033cb5f

View File

@@ -49,22 +49,32 @@ const useWebViewSetup = ({
const injectedJavaScript = useMemo(() => `
if (!window.cm) {
${shim.injectedJs('markdownEditorBundle')};
markdownEditorBundle.setUpLogger();
const parentClassName = ${JSON.stringify(editorOptions.parentElementClassName)};
const foundParent = document.getElementsByClassName(parentClassName).length > 0;
window.cm = markdownEditorBundle.initializeEditor(
${JSON.stringify(editorOptions)}
);
// On Android, injectedJavaScript can be run multiple times, including once before the
// document has loaded. To avoid logging an error each time the editor starts, don't throw
// if the parent element can't be found:
if (foundParent) {
${shim.injectedJs('markdownEditorBundle')};
markdownEditorBundle.setUpLogger();
${jumpToHashJs}
// Set the initial selection after jumping to the header -- the initial selection,
// if specified, should take precedence.
${setInitialSelectionJs}
${setInitialSearchJs}
window.cm = markdownEditorBundle.initializeEditor(
${JSON.stringify(editorOptions)}
);
window.onresize = () => {
cm.execCommand('scrollSelectionIntoView');
};
${jumpToHashJs}
// Set the initial selection after jumping to the header -- the initial selection,
// if specified, should take precedence.
${setInitialSelectionJs}
${setInitialSearchJs}
window.onresize = () => {
cm.execCommand('scrollSelectionIntoView');
};
} else {
console.log('No parent element found with class name ', parentClassName);
}
}
`, [jumpToHashJs, setInitialSearchJs, setInitialSelectionJs, editorOptions]);