From abde4fac67410a28b12c7c462c3ae6b490f01279 Mon Sep 17 00:00:00 2001 From: rekols Date: Wed, 29 Aug 2018 14:44:41 +0800 Subject: [PATCH] fix: switch theme to scroll to the next line. Change-Id: I6f14ccbc4aea817bc827d5013e520700289fb0ce feat: move to the first line after loadding the file. --- editor/src/editor.cpp | 1 + editor/src/texteditor.cpp | 14 ++++++++++---- editor/src/texteditor.h | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/editor/src/editor.cpp b/editor/src/editor.cpp index 80e1ba09..1d6daaed 100644 --- a/editor/src/editor.cpp +++ b/editor/src/editor.cpp @@ -180,6 +180,7 @@ void Editor::handleFileLoadFinished(const QString &encode, const QString &conten // update status. textEditor->setModified(false); + textEditor->moveFirstLine(); // load highlight. textEditor->loadHighlighter(); diff --git a/editor/src/texteditor.cpp b/editor/src/texteditor.cpp index 4cd5d51a..5b88121d 100644 --- a/editor/src/texteditor.cpp +++ b/editor/src/texteditor.cpp @@ -1300,6 +1300,13 @@ void TextEditor::setFontSize(int size) updateLineNumber(); } +void TextEditor::moveFirstLine() +{ + QTextCursor cursor = textCursor(); + cursor.movePosition(QTextCursor::Start); + setTextCursor(cursor); +} + void TextEditor::updateFont() { QFont font = document()->defaultFont(); @@ -1875,9 +1882,9 @@ void TextEditor::highlightCurrentLine() adjustScrollbarMargins(); // Keep current line at visible area. - if (cursorRect().top() + fontMetrics().height() >= rect().height()) { - scrollLineUp(); - } + // if (cursorRect().top() + fontMetrics().height() >= rect().height()) { + // scrollLineUp(); + // } } void TextEditor::updateLineNumber() @@ -1997,7 +2004,6 @@ void TextEditor::setTheme(const KSyntaxHighlighting::Theme &theme, QString theme } m_highlighter->rehighlight(); - lineNumberArea->update(); highlightCurrentLine(); diff --git a/editor/src/texteditor.h b/editor/src/texteditor.h index efe8ccbb..b18d97e1 100644 --- a/editor/src/texteditor.h +++ b/editor/src/texteditor.h @@ -103,6 +103,7 @@ class TextEditor : public QPlainTextEdit void setFontFamily(QString fontName); void setFontSize(int fontSize); + void moveFirstLine(); void updateFont(); void replaceAll(QString replaceText, QString withText); @@ -153,7 +154,7 @@ class TextEditor : public QPlainTextEdit void toggleComment(); void toggleBullet(); - void toggleBulletWithLine(int line, bool addBullet); + void toggleBulletWithLine(int tltine, bool addBullet); int getNextWordPosition(QTextCursor cursor, QTextCursor::MoveMode moveMode); int getPrevWordPosition(QTextCursor cursor, QTextCursor::MoveMode moveMode);