summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRicardo Markiewicz <gazer.arg@gmail.com>2013-11-29 03:16:40 (GMT)
committerRicardo Markiewicz <gazer.arg@gmail.com>2013-11-29 03:16:40 (GMT)
commit7b64944738d91eb2eef92f93f526cc29436adf15 (patch)
tree0b9ed5c7b215d9ca30806222d22aa0d8dc65133d /src
parentde2db22b5f82855b9cf42829c4dde3b4bd231273 (diff)
Try to keep cursor and scroll in place on refresh
When the file is saving, the cursor position was resetting to the top and you should keep scrolling by hand every time you save the file. This patch saves the scroll and cursor position and set it again after the file is refreshed so we can continue edition from where we were.
Diffstat (limited to 'src')
-rw-r--r--src/mainwin.cc9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/mainwin.cc b/src/mainwin.cc
index 5b986b1..8c21b20 100644
--- a/src/mainwin.cc
+++ b/src/mainwin.cc
@@ -75,6 +75,7 @@
#include <QSettings>
#include <QProgressDialog>
#include <QMutexLocker>
+#include <QScrollBar>
#include <fstream>
@@ -605,7 +606,15 @@ void MainWindow::refreshDocument()
reader.setCodec("UTF-8");
QString text = reader.readAll();
PRINTB("Loaded design '%s'.", this->fileName.toLocal8Bit().constData());
+ int y = editor->verticalScrollBar()->sliderPosition();
+ // Save current cursor position
+ QTextCursor cursor = editor->textCursor();
+ int n = cursor.position();
editor->setPlainText(text);
+ // Restore cursor position
+ cursor.setPosition(n);
+ editor->setTextCursor(cursor);
+ editor->verticalScrollBar()->setSliderPosition(y);
}
}
setCurrentOutput();
contact: Jan Huwald // Impressum