]> _ Git - fluidbook-toolbox.git/commitdiff
wip #7634 @2:00
authorsoufiane <soufiane@cubedesigners.com>
Mon, 28 Jul 2025 10:04:31 +0000 (12:04 +0200)
committersoufiane <soufiane@cubedesigners.com>
Mon, 28 Jul 2025 10:04:31 +0000 (12:04 +0200)
resources/markdowneditor/js/markdowneditor.js

index a5bcb538998c713b87120c2d61f4235a49cdba5c..9df2c913435b9beb13822fee772fd3ccb0c6ad37 100644 (file)
@@ -33,12 +33,19 @@ MarkdownEditor.prototype = {
         this.save = new MarkdowneditorSave(this);
         this.versions = new MarkdowneditorVersions(this);
         this.open = false
+        this.savedScroll = null;
 
         const $this = this
         this.initIcons();
         this.markdown();
         this.changePage();
 
+        this.editor.addHook('afterPreviewRender', () => {
+            if (this.savedScroll !== undefined) {
+                $(".toastui-editor-md-preview").scrollTop(this.savedScroll);
+                this.savedScroll = undefined;
+            }
+        });
 
         $(window).on('hashchange', function () {
             /*if ($this.maskHashEvent) {
@@ -160,11 +167,11 @@ MarkdownEditor.prototype = {
         if(this.undo.states[this.getCurrentPage()] !== undefined) {
             const state = this.undo.states[this.getCurrentPage()]
             const lastKey = state.length - 1;
-            this.editor.setMarkdown(state[lastKey])
+            this.editor.setMarkdown(state[lastKey],false)
             this.editor.moveCursorToStart(true)
         }else {
             this.contentMarkdown = MARKDOWN_DATA[this.currentPage] ?? ''
-            this.editor.setMarkdown(this.contentMarkdown)
+            this.editor.setMarkdown(this.contentMarkdown, false)
             this.editor.moveCursorToStart(true)
         }
     },
@@ -188,14 +195,12 @@ MarkdownEditor.prototype = {
         this.editor.getMarkdown();
     },
 
-    setCurrentState: function (state,scroll) {
-        MARKDOWN_DATA[this.currentPage] = state
-        const editorElement = $(".toastui-editor-md-preview")[0];
-        const scrollTop = editorElement.scrollTop;
-        this.editor.moveCursorToEnd(false);
+    setCurrentState: function (state) {
+        MARKDOWN_DATA[this.currentPage] = state;
+        let scroll = this.editor.getScrollTop();
         this.editor.setMarkdown(state, false);
-        this.editor.moveCursorToEnd(false);
-        this.editor.getCurrentModeEditor().blur();
+        this.savedScroll = $(".toastui-editor-md-preview").scrollTop();
+        this.editor.setScrollTop(scroll);
 
         //this.editor.moveCursorToStart(true)
     },