Git: Fix filling commit selection combobox for log

Broken by commit cbb70513bf, 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 <orgads@gmail.com>
This commit is contained in:
Andre Hartmann
2020-05-16 17:37:33 +02:00
committed by André Hartmann
parent 9c71e41ad1
commit d1b0966996
5 changed files with 29 additions and 7 deletions

View File

@@ -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();

View File

@@ -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,6 +180,7 @@ void DiffAndLogHighlighter::highlightBlock(const QString &text)
const int length = text.length();
const TextEditor::TextStyle format = d->analyzeLine(text);
if (d->m_enabled) {
if (format == TextEditor::C_ADDED_LINE) {
// Mark trailing whitespace.
const int trimmedLen = trimmedLength(text);
@@ -190,6 +192,7 @@ void DiffAndLogHighlighter::highlightBlock(const QString &text)
} else {
formatSpaces(text);
}
}
// codefolding:
TextEditor::TextBlockUserData *data =
@@ -241,4 +244,9 @@ void DiffAndLogHighlighter::setFontSettings(const TextEditor::FontSettings &font
d->updateOtherFormats();
}
void DiffAndLogHighlighter::setEnabled(bool e)
{
d->m_enabled = e;
}
} // namespace VcsBase

View File

@@ -53,6 +53,8 @@ public:
void setFontSettings(const TextEditor::FontSettings &fontSettings) override;
void setEnabled(bool e);
private:
friend class DiffAndLogHighlighterPrivate;
DiffAndLogHighlighterPrivate *const d;

View File

@@ -828,6 +828,12 @@ void VcsBaseEditorWidget::setFileLogAnnotateEnabled(bool e)
d->m_fileLogAnnotateEnabled = e;
}
void VcsBaseEditorWidget::setHighlightingEnabled(bool e)
{
auto dh = static_cast<DiffAndLogHighlighter *>(textDocument()->syntaxHighlighter());
dh->setEnabled(e);
}
QString VcsBaseEditorWidget::workingDirectory() const
{
return d->m_workingDirectory;

View File

@@ -192,6 +192,8 @@ public:
bool isFileLogAnnotateEnabled() const;
void setFileLogAnnotateEnabled(bool e);
void setHighlightingEnabled(bool e);
QTextCodec *codec() const;
void setCodec(QTextCodec *);