TextEditor: Preserve preview scroll position across page refreshes

This commit is contained in:
Sahan Fernando 2020-07-20 22:22:07 +10:00 committed by Andreas Kling
commit ccc929dcf9
Notes: sideshowbarker 2024-07-19 04:42:19 +09:00

View file

@ -606,11 +606,15 @@ void TextEditorWidget::update_markdown_preview()
auto document = Markdown::Document::parse(m_editor->text()); auto document = Markdown::Document::parse(m_editor->text());
if (document) { if (document) {
auto html = document->render_to_html(); 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->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() 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->load_html(m_editor->text(), URL::create_with_file_protocol(m_path));
m_page_view->scroll_into_view(current_scroll_pos, true, true);
} }