summaryrefslogtreecommitdiff
path: root/src/editor.cc
diff options
context:
space:
mode:
authorRicardo Markiewicz <gazer.arg@gmail.com>2013-11-29 04:40:28 (GMT)
committerRicardo Markiewicz <gazer.arg@gmail.com>2013-11-29 04:40:28 (GMT)
commitafe1fbcb53ff286b2f6efdb99efb6ed9947304f9 (patch)
tree0f95851e9aa974d156272631562820dd9a206a65 /src/editor.cc
parent7b64944738d91eb2eef92f93f526cc29436adf15 (diff)
Move main code inside Editor class
Before open a new file now we cleanup the Editor, so the new file get the cursor on the first character.
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