[utilities/kate] addons/git-blame: Git blame tooltip improvements
Christoph Cullmann <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 4324fd9819bc9154296e68feeade0596f2c1370c by Christoph Cullmann, on behalf of Leo Ruggeri.
Committed on 25/07/2026 at 11:45.
Pushed by cullmann into branch 'master'.
Git blame tooltip improvements
- Adjust text and separator lines margins
- Use commit hash as "open commit" link
- Use the same font logic as text hint tooltip
M +16 -7 addons/git-blame/gitblametooltip.cpp
M +8 -7 addons/git-blame/kategitblameplugin.cpp
https://invent.kde.org/utilities/kate/-/commit/4324fd9819bc9154296e68feeade0596f2c1370c
diff --git a/addons/git-blame/gitblametooltip.cpp b/addons/git-blame/gitblametooltip.cpp
index 5602171e88..dafce0ec43 100644
--- a/addons/git-blame/gitblametooltip.cpp
+++ b/addons/git-blame/gitblametooltip.cpp
@@ -69,20 +69,28 @@ public:
bool inDiff = false;
+ QString preTagOpen = QStringLiteral("<pre style='margin: 3; white-space: pre-wrap;'>");
+ QString preTagClose = QStringLiteral("</pre>");
+
KSyntaxHighlighting::State state;
- out << "<pre>";
+ out << preTagOpen;
while (!in.atEnd()) {
currentLine = in.readLine();
// Link to open the tree view, insert as is
- if (currentLine.startsWith(QLatin1String("<a href"))) {
- out << currentLine;
+ if (currentLine.contains(QLatin1String("<a href"))) {
+ out << currentLine << "\n";
+ continue;
+ }
+
+ if (currentLine.startsWith(QLatin1String(" "))) {
+ out << currentLine.mid(4) << "\n";
continue;
}
// allow empty lines in code blocks, no ruler here
if (!inDiff && currentLine.isEmpty()) {
- out << "<hr>";
+ out << preTagClose << "<hr>" << preTagOpen;
continue;
}
@@ -94,7 +102,7 @@ public:
state = highlightLine(currentLine, state);
out << "\n";
}
- out << "</pre>";
+ out << preTagClose;
}
QString html() const
@@ -144,7 +152,6 @@ public:
: QTextBrowser(nullptr)
{
setWindowFlags(Qt::FramelessWindowHint | Qt::BypassGraphicsProxyWidget | Qt::ToolTip);
- setWordWrapMode(QTextOption::NoWrap);
const auto margin = style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing, nullptr, this);
document()->setDocumentMargin(margin);
setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
@@ -170,7 +177,9 @@ public:
pal.setColor(QPalette::Text, normal);
setPalette(pal);
- setFont(Utils::editorFont());
+ auto newFont = Utils::editorFont();
+ newFont.setPointSize(font().pointSize());
+ setFont(newFont);
};
updateColors(KTextEditor::Editor::instance());
connect(KTextEditor::Editor::instance(), &KTextEditor::Editor::configChanged, this, updateColors);
diff --git a/addons/git-blame/kategitblameplugin.cpp b/addons/git-blame/kategitblameplugin.cpp
index f6509d008f..d4fb419803 100644
--- a/addons/git-blame/kategitblameplugin.cpp
+++ b/addons/git-blame/kategitblameplugin.cpp
@@ -430,13 +430,14 @@ void KateGitBlamePluginView::showFinished(int exitCode, QProcess::ExitStatus exi
return;
}
- // Find 'Date:'
- int dateIdx = stdOut.indexOf(QStringLiteral("Date:"));
- if (dateIdx != -1) {
- int newLine = stdOut.indexOf(u'\n', dateIdx);
- if (newLine != -1) {
- QString btn = QLatin1String("\n<a href=\"%1\">Click To Show Commit In Tree View</a>\n").arg(commitHashArg);
- stdOut.insert(newLine + 1, btn);
+ // Replace commit hash with html link
+ const QString prefix = QLatin1String("commit ");
+ int start = stdOut.indexOf(prefix);
+ if (start != -1) {
+ start += prefix.length();
+ int end = stdOut.indexOf(u'\n', start);
+ if (end != -1) {
+ stdOut.replace(start, end - start, QLatin1String("<a href=\"%1\">%1</a>").arg(commitHashArg));
}
}