From 98f4f35e16ce4a6120421027e16b2081008273c6 Mon Sep 17 00:00:00 2001 From: soufiane Date: Mon, 28 Jul 2025 12:04:31 +0200 Subject: [PATCH] wip #7634 @2:00 --- resources/markdowneditor/js/markdowneditor.js | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/resources/markdowneditor/js/markdowneditor.js b/resources/markdowneditor/js/markdowneditor.js index a5bcb5389..9df2c9134 100644 --- a/resources/markdowneditor/js/markdowneditor.js +++ b/resources/markdowneditor/js/markdowneditor.js @@ -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) }, -- 2.39.5