]> BookStack Code Mirror - bookstack/commitdiff
Fixed md editor refactoring issues after manual test
authorDan Brown <redacted>
Sat, 26 Nov 2022 21:33:39 +0000 (21:33 +0000)
committerDan Brown <redacted>
Sat, 26 Nov 2022 21:33:39 +0000 (21:33 +0000)
Testing was a full manual feature test of each piece of supported logic
defined in the code.

resources/js/markdown/actions.js
resources/js/markdown/codemirror.js
resources/js/markdown/display.js

index 96093d833942bccd39878c8acd4f3dfe9b54abe6..96f9b263c9a7db4be02bc08273c32043e9696b0a 100644 (file)
@@ -78,7 +78,7 @@ export class Actions {
 
             const data = {
                 image: pngData,
-                uploaded_to: Number(this.pageId),
+                uploaded_to: Number(this.editor.config.pageId),
             };
 
             window.$http.post("/images/drawio", data).then(resp => {
@@ -368,7 +368,7 @@ export class Actions {
         const scroll = this.editor.cm.getScrollInfo();
         const atEnd = scroll.top + scroll.clientHeight === scroll.height;
         if (atEnd) {
-            editor.display.scrollToIndex(-1);
+            this.editor.display.scrollToIndex(-1);
             return;
         }
 
@@ -377,7 +377,7 @@ export class Actions {
         const parser = new DOMParser();
         const doc = parser.parseFromString(this.editor.markdown.render(range), 'text/html');
         const totalLines = doc.documentElement.querySelectorAll('body > *');
-        editor.display.scrollToIndex(totalLines.length);
+        this.editor.display.scrollToIndex(totalLines.length);
     }
 
     /**
@@ -404,7 +404,7 @@ export class Actions {
         const cursorPos = this.editor.cm.coordsChar({left: event.pageX, top: event.pageY});
         this.editor.cm.setCursor(cursorPos);
         for (const image of images) {
-            editor.actions.uploadImage(image);
+            this.editor.actions.uploadImage(image);
         }
     }
 }
\ No newline at end of file
index 27491902a1679fd912828cd73ffcaff7e78d4922..06860b929cddb3c5a73bb888af4dc2e91689aed7 100644 (file)
@@ -23,7 +23,7 @@ export async function init(editor) {
     cm.on('change', (instance, changeObj) => editor.actions.updateAndRender());
 
     // Handle scroll to sync display view
-    const onScrollDebounced = debounce(editor.actions.syncDisplayPosition, 100, false);
+    const onScrollDebounced = debounce(editor.actions.syncDisplayPosition.bind(editor.actions), 100, false);
     cm.on('scroll', instance => onScrollDebounced(instance));
 
     // Handle image paste
index 742198b46065f43c4dd7169ccf9f7c6eb1cc001d..7e1925431cf284aa460be22abacc995c1cdd10c4 100644 (file)
@@ -26,7 +26,7 @@ export class Display {
         this.doc.body.className = 'page-content';
 
         // Prevent markdown display link click redirect
-        this.doc.addEventListener('click', this.onDisplayClick)
+        this.doc.addEventListener('click', this.onDisplayClick.bind(this));
     }
 
     /**
@@ -91,8 +91,8 @@ export class Display {
      * @param {Number} index
      */
     scrollToIndex(index) {
-        const elems = this.doc.body.children;
-        if (elems.length <= index) return;
+        const elems = this.doc.body?.children[0]?.children;
+        if (elems && elems.length <= index) return;
 
         const topElem = (index === -1) ? elems[elems.length-1] : elems[index];
         topElem.scrollIntoView({ block: 'start', inline: 'nearest', behavior: 'smooth'});