diff options
author | Marius Kintel <marius@kintel.net> | 2013-12-09 04:12:13 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2013-12-09 04:12:13 (GMT) |
commit | 462d4d447885594629fefb8a658f9f1d079bcc44 (patch) | |
tree | 6690951e4f814b87a1a372a913b75ceda1f6cc1a /src/editor.cc | |
parent | 435e0c021c5018ee5de69d3218c3e31c8ab75be5 (diff) | |
parent | 33c34b6f7c43d19bbfa3bf91e7b577bcc062e5bd (diff) |
Merge branch 'master' into travis
Diffstat (limited to 'src/editor.cc')
-rw-r--r-- | src/editor.cc | 14 |
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); + } +} |