From d1b0966996ffca71fadb4978c11a06ed3d6928f7 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sat, 16 May 2020 17:37:33 +0200 Subject: [PATCH] Git: Fix filling commit selection combobox for log Broken by commit cbb70513bfa935, which changed the format for the normal log to override the highlighter. We still need the hightlighter for the log with diff. Therefore, a separation between highlighting and parsing the log is needed to populate the combobox for commit selection again. Change-Id: I902ce548fc25875f2cd67b165283ff1236329afa Reviewed-by: Orgad Shaneh --- src/plugins/git/gitclient.cpp | 8 ++++++-- src/plugins/vcsbase/diffandloghighlighter.cpp | 18 +++++++++++++----- src/plugins/vcsbase/diffandloghighlighter.h | 2 ++ src/plugins/vcsbase/vcsbaseeditor.cpp | 6 ++++++ src/plugins/vcsbase/vcsbaseeditor.h | 2 ++ 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index 38409dfcc02..1854c359e1b 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -1048,7 +1048,7 @@ static QStringList normalLogArguments() const QString logArgs = QStringLiteral( "--pretty=format:" - "Commit: %C(%1)%H%Creset %C(%2)%d%Creset%n" + "commit %C(%1)%H%Creset %C(%2)%d%Creset%n" "Author: %C(%3)%an <%ae>%Creset%n" "Date: %C(%4)%cD%Creset%n%n" "%C(%5)%s%Creset%n%n%b%n" @@ -1092,8 +1092,12 @@ void GitClient::log(const QString &workingDirectory, const QString &fileName, arguments << "-n" << QString::number(logCount); arguments << argWidget->arguments(); - if (arguments.contains(patchOption)) + if (arguments.contains(patchOption)) { arguments.removeAll(colorOption); + editor->setHighlightingEnabled(true); + } else { + editor->setHighlightingEnabled(false); + } if (!arguments.contains(graphOption) && !arguments.contains(patchOption)) arguments << normalLogArguments(); diff --git a/src/plugins/vcsbase/diffandloghighlighter.cpp b/src/plugins/vcsbase/diffandloghighlighter.cpp index a2f0836f35b..220b3b1ae9d 100644 --- a/src/plugins/vcsbase/diffandloghighlighter.cpp +++ b/src/plugins/vcsbase/diffandloghighlighter.cpp @@ -115,6 +115,7 @@ public: QTextCharFormat m_addedTrailingWhiteSpaceFormat; Internal::FoldingState m_foldingState; + bool m_enabled = true; }; TextEditor::TextStyle DiffAndLogHighlighterPrivate::analyzeLine(const QString &text) const @@ -179,16 +180,18 @@ void DiffAndLogHighlighter::highlightBlock(const QString &text) const int length = text.length(); const TextEditor::TextStyle format = d->analyzeLine(text); - if (format == TextEditor::C_ADDED_LINE) { + if (d->m_enabled) { + if (format == TextEditor::C_ADDED_LINE) { // Mark trailing whitespace. const int trimmedLen = trimmedLength(text); setFormatWithSpaces(text, 0, trimmedLen, formatForCategory(format)); if (trimmedLen != length) setFormat(trimmedLen, length - trimmedLen, d->m_addedTrailingWhiteSpaceFormat); - } else if (format != TextEditor::C_TEXT) { - setFormatWithSpaces(text, 0, length, formatForCategory(format)); - } else { - formatSpaces(text); + } else if (format != TextEditor::C_TEXT) { + setFormatWithSpaces(text, 0, length, formatForCategory(format)); + } else { + formatSpaces(text); + } } // codefolding: @@ -241,4 +244,9 @@ void DiffAndLogHighlighter::setFontSettings(const TextEditor::FontSettings &font d->updateOtherFormats(); } +void DiffAndLogHighlighter::setEnabled(bool e) +{ + d->m_enabled = e; +} + } // namespace VcsBase diff --git a/src/plugins/vcsbase/diffandloghighlighter.h b/src/plugins/vcsbase/diffandloghighlighter.h index c43f4a510d7..050374c3436 100644 --- a/src/plugins/vcsbase/diffandloghighlighter.h +++ b/src/plugins/vcsbase/diffandloghighlighter.h @@ -53,6 +53,8 @@ public: void setFontSettings(const TextEditor::FontSettings &fontSettings) override; + void setEnabled(bool e); + private: friend class DiffAndLogHighlighterPrivate; DiffAndLogHighlighterPrivate *const d; diff --git a/src/plugins/vcsbase/vcsbaseeditor.cpp b/src/plugins/vcsbase/vcsbaseeditor.cpp index bed1d5c8632..37fc44bacd4 100644 --- a/src/plugins/vcsbase/vcsbaseeditor.cpp +++ b/src/plugins/vcsbase/vcsbaseeditor.cpp @@ -828,6 +828,12 @@ void VcsBaseEditorWidget::setFileLogAnnotateEnabled(bool e) d->m_fileLogAnnotateEnabled = e; } +void VcsBaseEditorWidget::setHighlightingEnabled(bool e) +{ + auto dh = static_cast(textDocument()->syntaxHighlighter()); + dh->setEnabled(e); +} + QString VcsBaseEditorWidget::workingDirectory() const { return d->m_workingDirectory; diff --git a/src/plugins/vcsbase/vcsbaseeditor.h b/src/plugins/vcsbase/vcsbaseeditor.h index 5340a3d4b26..72df0289ae0 100644 --- a/src/plugins/vcsbase/vcsbaseeditor.h +++ b/src/plugins/vcsbase/vcsbaseeditor.h @@ -192,6 +192,8 @@ public: bool isFileLogAnnotateEnabled() const; void setFileLogAnnotateEnabled(bool e); + void setHighlightingEnabled(bool e); + QTextCodec *codec() const; void setCodec(QTextCodec *);