X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/6b84a76af1917ff8e53c4636cb5fe08d1b40ccdd..6ca8ccd330bc858aa6b8fa6e3ecd23fab013ffba:/resources/assets/js/components/wysiwyg-editor.js diff --git a/resources/assets/js/components/wysiwyg-editor.js b/resources/assets/js/components/wysiwyg-editor.js index f7e9bfeed..a8a2ff175 100644 --- a/resources/assets/js/components/wysiwyg-editor.js +++ b/resources/assets/js/components/wysiwyg-editor.js @@ -483,13 +483,36 @@ class WysiwygEditor { }, setup: function (editor) { - editor.on('init ExecCommand change input NodeChange ObjectResized', editorChange); + editor.on('ExecCommand change input NodeChange ObjectResized', editorChange); + + editor.on('init', () => { + editorChange(); + // Scroll to the content if needed. + const queryParams = (new URL(window.location)).searchParams; + const scrollId = queryParams.get('content-id'); + if (scrollId) { + scrollToText(scrollId); + } + }); function editorChange() { let content = editor.getContent(); window.$events.emit('editor-html-change', content); } + function scrollToText(scrollId) { + const element = editor.dom.get(encodeURIComponent(scrollId).replace(/!/g, '%21')); + if (!element) { + return; + } + + // scroll the element into the view and put the cursor at the end. + element.scrollIntoView(); + editor.selection.select(element, true); + editor.selection.collapse(false); + editor.focus(); + } + window.$events.listen('editor-html-update', html => { editor.setContent(html); editor.selection.select(editor.getBody(), true);