X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/40ca50e44f3ca0f648d915dc73ff205309730f07..refs/pull/3238/head:/resources/js/components/markdown-editor.js diff --git a/resources/js/components/markdown-editor.js b/resources/js/components/markdown-editor.js index a90f74e27..a14047d2f 100644 --- a/resources/js/components/markdown-editor.js +++ b/resources/js/components/markdown-editor.js @@ -112,6 +112,11 @@ class MarkdownEditor { if (scrollText) { this.scrollToText(scrollText); } + + // Refresh CodeMirror on container resize + const resizeDebounced = debounce(() => code.updateLayout(this.cm), 100, false); + const observer = new ResizeObserver(resizeDebounced); + observer.observe(this.elem); } // Update the input content and render the display. @@ -395,8 +400,9 @@ class MarkdownEditor { actionInsertImage() { const cursorPos = this.cm.getCursor('from'); window.ImageManager.show(image => { + const imageUrl = image.thumbs.display || image.url; let selectedText = this.cm.getSelection(); - let newText = "[![" + (selectedText || image.name) + "](" + image.thumbs.display + ")](" + image.url + ")"; + let newText = "[![" + (selectedText || image.name) + "](" + imageUrl + ")](" + image.url + ")"; this.cm.focus(); this.cm.replaceSelection(newText); this.cm.setCursor(cursorPos.line, cursorPos.ch + newText.length);