mirror of
				https://github.com/BookStackApp/BookStack.git
				synced 2025-11-03 02:13:16 +03:00 
			
		
		
		
	Fixed md editor refactoring issues after manual test
Testing was a full manual feature test of each piece of supported logic defined in the code.
This commit is contained in:
		@@ -78,7 +78,7 @@ export class Actions {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            const data = {
 | 
					            const data = {
 | 
				
			||||||
                image: pngData,
 | 
					                image: pngData,
 | 
				
			||||||
                uploaded_to: Number(this.pageId),
 | 
					                uploaded_to: Number(this.editor.config.pageId),
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            window.$http.post("/images/drawio", data).then(resp => {
 | 
					            window.$http.post("/images/drawio", data).then(resp => {
 | 
				
			||||||
@@ -368,7 +368,7 @@ export class Actions {
 | 
				
			|||||||
        const scroll = this.editor.cm.getScrollInfo();
 | 
					        const scroll = this.editor.cm.getScrollInfo();
 | 
				
			||||||
        const atEnd = scroll.top + scroll.clientHeight === scroll.height;
 | 
					        const atEnd = scroll.top + scroll.clientHeight === scroll.height;
 | 
				
			||||||
        if (atEnd) {
 | 
					        if (atEnd) {
 | 
				
			||||||
            editor.display.scrollToIndex(-1);
 | 
					            this.editor.display.scrollToIndex(-1);
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -377,7 +377,7 @@ export class Actions {
 | 
				
			|||||||
        const parser = new DOMParser();
 | 
					        const parser = new DOMParser();
 | 
				
			||||||
        const doc = parser.parseFromString(this.editor.markdown.render(range), 'text/html');
 | 
					        const doc = parser.parseFromString(this.editor.markdown.render(range), 'text/html');
 | 
				
			||||||
        const totalLines = doc.documentElement.querySelectorAll('body > *');
 | 
					        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});
 | 
					        const cursorPos = this.editor.cm.coordsChar({left: event.pageX, top: event.pageY});
 | 
				
			||||||
        this.editor.cm.setCursor(cursorPos);
 | 
					        this.editor.cm.setCursor(cursorPos);
 | 
				
			||||||
        for (const image of images) {
 | 
					        for (const image of images) {
 | 
				
			||||||
            editor.actions.uploadImage(image);
 | 
					            this.editor.actions.uploadImage(image);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -23,7 +23,7 @@ export async function init(editor) {
 | 
				
			|||||||
    cm.on('change', (instance, changeObj) => editor.actions.updateAndRender());
 | 
					    cm.on('change', (instance, changeObj) => editor.actions.updateAndRender());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Handle scroll to sync display view
 | 
					    // 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));
 | 
					    cm.on('scroll', instance => onScrollDebounced(instance));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Handle image paste
 | 
					    // Handle image paste
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,7 +26,7 @@ export class Display {
 | 
				
			|||||||
        this.doc.body.className = 'page-content';
 | 
					        this.doc.body.className = 'page-content';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Prevent markdown display link click redirect
 | 
					        // 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
 | 
					     * @param {Number} index
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    scrollToIndex(index) {
 | 
					    scrollToIndex(index) {
 | 
				
			||||||
        const elems = this.doc.body.children;
 | 
					        const elems = this.doc.body?.children[0]?.children;
 | 
				
			||||||
        if (elems.length <= index) return;
 | 
					        if (elems && elems.length <= index) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const topElem = (index === -1) ? elems[elems.length-1] : elems[index];
 | 
					        const topElem = (index === -1) ? elems[elems.length-1] : elems[index];
 | 
				
			||||||
        topElem.scrollIntoView({ block: 'start', inline: 'nearest', behavior: 'smooth'});
 | 
					        topElem.scrollIntoView({ block: 'start', inline: 'nearest', behavior: 'smooth'});
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user