From ccc929dcf90af7d2e0d6936be0f6b80d526f0ce7 Mon Sep 17 00:00:00 2001 From: Sahan Fernando Date: Mon, 20 Jul 2020 22:22:07 +1000 Subject: [PATCH] TextEditor: Preserve preview scroll position across page refreshes --- Applications/TextEditor/TextEditorWidget.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Applications/TextEditor/TextEditorWidget.cpp b/Applications/TextEditor/TextEditorWidget.cpp index ed4e4c26f1..f06c2dda71 100644 --- a/Applications/TextEditor/TextEditorWidget.cpp +++ b/Applications/TextEditor/TextEditorWidget.cpp @@ -606,11 +606,15 @@ void TextEditorWidget::update_markdown_preview() auto document = Markdown::Document::parse(m_editor->text()); if (document) { auto html = document->render_to_html(); + auto current_scroll_pos = m_page_view->visible_content_rect(); m_page_view->load_html(html, URL::create_with_file_protocol(m_path)); + m_page_view->scroll_into_view(current_scroll_pos, true, true); } } void TextEditorWidget::update_html_preview() { + auto current_scroll_pos = m_page_view->visible_content_rect(); m_page_view->load_html(m_editor->text(), URL::create_with_file_protocol(m_path)); + m_page_view->scroll_into_view(current_scroll_pos, true, true); }