changeset 28360:668b38ab90f7

fix jumping vertical scrollbar when file is saved in editor (bug #58418) * file-editor-tab.cc: save the vertical scroll position before the trailing spaces are trimmed, and restore the position after the trimmed data is put back into the m_edit_area
author Markus Meisinger <chloros2@gmx.de>
date Thu, 21 May 2020 21:02:29 +0200
parents 75c87b15bcee
children 5c39263f1d70
files libgui/src/m-editor/file-editor-tab.cc
diffstat 1 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Sun May 24 10:41:11 2020 +0200
+++ b/libgui/src/m-editor/file-editor-tab.cc	Thu May 21 21:02:29 2020 +0200
@@ -44,6 +44,7 @@
 #include <QMessageBox>
 #include <QPrintDialog>
 #include <QPushButton>
+#include <QScrollBar>
 #include <QStyle>
 #include <QTextBlock>
 #include <QTextCodec>
@@ -2294,7 +2295,8 @@
     if (settings->value (ed_rm_trailing_spaces).toBool ())
       {
         int line, col;
-        m_edit_area->getCursorPosition (&line,&col);
+        m_edit_area->getCursorPosition (&line, &col);
+        const int vscroll_pos = m_edit_area->verticalScrollBar()->value();
 
         QString eol = eol_string ();
         QString edit_text = m_edit_area->text ();
@@ -2304,7 +2306,8 @@
         edit_text.chop (edit_text.length () - idx - 1); // Last line
 
         m_edit_area->setText (edit_text);
-        m_edit_area->setCursorPosition (line,col);
+        m_edit_area->setCursorPosition (line, col);
+        m_edit_area->verticalScrollBar()->setValue(vscroll_pos);
       }
 
     // Save the file