]> BookStack Code Mirror - bookstack/blobdiff - resources/js/markdown/actions.js
API Docs: Allowed multi-paragraph descriptions
[bookstack] / resources / js / markdown / actions.js
index 514bff87d86b87379a49a75035958f637394bd39..f66b7921dea70b6951857d5c259592d0a51220ef 100644 (file)
@@ -433,7 +433,9 @@ export class Actions {
      */
     #setText(text, selectionRange = null) {
         selectionRange = selectionRange || this.#getSelectionRange();
-        this.#dispatchChange(0, this.editor.cm.state.doc.length, text, selectionRange.from);
+        const newDoc = this.editor.cm.state.toText(text);
+        const newSelectFrom = Math.min(selectionRange.from, newDoc.length);
+        this.#dispatchChange(0, this.editor.cm.state.doc.length, text, newSelectFrom);
         this.focus();
     }