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(() => ` const injectedJavaScript = useMemo(() => `
if (!window.cm) { if (!window.cm) {
${shim.injectedJs('markdownEditorBundle')}; const parentClassName = ${JSON.stringify(editorOptions.parentElementClassName)};
markdownEditorBundle.setUpLogger(); const foundParent = document.getElementsByClassName(parentClassName).length > 0;
window.cm = markdownEditorBundle.initializeEditor( // On Android, injectedJavaScript can be run multiple times, including once before the
${JSON.stringify(editorOptions)} // 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} window.cm = markdownEditorBundle.initializeEditor(
// Set the initial selection after jumping to the header -- the initial selection, ${JSON.stringify(editorOptions)}
// if specified, should take precedence. );
${setInitialSelectionJs}
${setInitialSearchJs}
window.onresize = () => { ${jumpToHashJs}
cm.execCommand('scrollSelectionIntoView'); // 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]); `, [jumpToHashJs, setInitialSearchJs, setInitialSelectionJs, editorOptions]);