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,6 +49,13 @@ const useWebViewSetup = ({
const injectedJavaScript = useMemo(() => ` const injectedJavaScript = useMemo(() => `
if (!window.cm) { if (!window.cm) {
const parentClassName = ${JSON.stringify(editorOptions.parentElementClassName)};
const foundParent = document.getElementsByClassName(parentClassName).length > 0;
// 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')}; ${shim.injectedJs('markdownEditorBundle')};
markdownEditorBundle.setUpLogger(); markdownEditorBundle.setUpLogger();
@@ -65,6 +72,9 @@ const useWebViewSetup = ({
window.onresize = () => { window.onresize = () => {
cm.execCommand('scrollSelectionIntoView'); cm.execCommand('scrollSelectionIntoView');
}; };
} else {
console.log('No parent element found with class name ', parentClassName);
}
} }
`, [jumpToHashJs, setInitialSearchJs, setInitialSelectionJs, editorOptions]); `, [jumpToHashJs, setInitialSearchJs, setInitialSelectionJs, editorOptions]);