From 7b64944738d91eb2eef92f93f526cc29436adf15 Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Fri, 29 Nov 2013 00:16:40 -0300 Subject: 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. 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 #include #include +#include #include @@ -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(); -- cgit v0.10.1