summaryrefslogtreecommitdiff
path: root/src/editor.cc
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2013-11-30 17:11:58 (GMT)
committerMarius Kintel <marius@kintel.net>2013-11-30 17:11:58 (GMT)
commit961c380c840882da246aad1c30928f106aea8747 (patch)
tree0f95851e9aa974d156272631562820dd9a206a65 /src/editor.cc
parentde2db22b5f82855b9cf42829c4dde3b4bd231273 (diff)
parentafe1fbcb53ff286b2f6efdb99efb6ed9947304f9 (diff)
Merge pull request #553 from Gazer/editor_improvements
Keep cursor position on save
Diffstat (limited to 'src/editor.cc')
-rw-r--r--src/editor.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/editor.cc b/src/editor.cc
index 08bf005..069101f 100644
--- a/src/editor.cc
+++ b/src/editor.cc
@@ -108,3 +108,17 @@ void Editor::wheelEvent ( QWheelEvent * event )
}
}
+void Editor::setPlainText(const QString &text)
+{
+ int y = verticalScrollBar()->sliderPosition();
+ // Save current cursor position
+ QTextCursor cursor = textCursor();
+ int n = cursor.position();
+ QTextEdit::setPlainText(text);
+ // Restore cursor position
+ if (n < text.length()) {
+ cursor.setPosition(n);
+ setTextCursor(cursor);
+ verticalScrollBar()->setSliderPosition(y);
+ }
+}
contact: Jan Huwald // Impressum