X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/58cadce052f5cc3c9ce2bc12f88a93cac310699a..refs/pull/4389/head:/resources/js/wysiwyg/plugin-codeeditor.js diff --git a/resources/js/wysiwyg/plugin-codeeditor.js b/resources/js/wysiwyg/plugin-codeeditor.js index fa3804ea8..2fe2ac26a 100644 --- a/resources/js/wysiwyg/plugin-codeeditor.js +++ b/resources/js/wysiwyg/plugin-codeeditor.js @@ -9,9 +9,16 @@ function elemIsCodeBlock(elem) { * @param {function(string, string)} callback (Receives (code: string,language: string) */ function showPopup(editor, code, language, callback) { - window.$components.first('code-editor').open(code, language, (newCode, newLang) => { + /** @var {CodeEditor} codeEditor * */ + const codeEditor = window.$components.first('code-editor'); + const bookMark = editor.selection.getBookmark(); + codeEditor.open(code, language, (newCode, newLang) => { callback(newCode, newLang); editor.focus(); + editor.selection.moveToBookmark(bookMark); + }, () => { + editor.focus(); + editor.selection.moveToBookmark(bookMark); }); } @@ -46,8 +53,8 @@ function defineCodeBlockCustomElement(editor) { super(); this.attachShadow({mode: 'open'}); - const stylesToCopy = document.querySelectorAll('link[rel="stylesheet"]:not([media="print"])'); - const copiedStyles = Array.from(stylesToCopy).map(styleEl => styleEl.cloneNode(false)); + const stylesToCopy = document.head.querySelectorAll('link[rel="stylesheet"]:not([media="print"]),style'); + const copiedStyles = Array.from(stylesToCopy).map(styleEl => styleEl.cloneNode(true)); const cmContainer = document.createElement('div'); cmContainer.style.pointerEvents = 'none';