Skip to content

Commit

Permalink
fix: switch theme to scroll to the next line.
Browse files Browse the repository at this point in the history
Change-Id: I6f14ccbc4aea817bc827d5013e520700289fb0ce
feat: move to the first line after loadding the file.
  • Loading branch information
rekols committed Aug 29, 2018
1 parent 992f541 commit abde4fa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions editor/src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ void Editor::handleFileLoadFinished(const QString &encode, const QString &conten

// update status.
textEditor->setModified(false);
textEditor->moveFirstLine();

// load highlight.
textEditor->loadHighlighter();
Expand Down
14 changes: 10 additions & 4 deletions editor/src/texteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -1997,7 +2004,6 @@ void TextEditor::setTheme(const KSyntaxHighlighting::Theme &theme, QString theme
}

m_highlighter->rehighlight();

lineNumberArea->update();

highlightCurrentLine();
Expand Down
3 changes: 2 additions & 1 deletion editor/src/texteditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit abde4fa

Please sign in to comment.