aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/git
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2022-11-21 16:20:30 +0200
committerOrgad Shaneh <orgads@gmail.com>2022-11-21 15:53:13 +0000
commit3a7fee0cc659393694cce125dcbb2b64c179b1bb (patch)
tree3082011d47ba32fc6b936e22fda67754bbf7dc58 /src/plugins/git
parent252179b9383bb98ebfcaf89d0dc3d19a063d7669 (diff)
Git: Fix crash when closing last editor
before instant blame was activated. Change-Id: I8a8acf6dc58cb25f7c10c1dfa08e3b7f6bae3e76 Reviewed-by: André Hartmann <aha_1980@gmx.de>
Diffstat (limited to 'src/plugins/git')
-rw-r--r--src/plugins/git/gitplugin.cpp39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp
index 66969b4df5..aee5fe4241 100644
--- a/src/plugins/git/gitplugin.cpp
+++ b/src/plugins/git/gitplugin.cpp
@@ -236,8 +236,6 @@ public:
}
};
-static std::unique_ptr<BlameMark> m_blameMark;
-
// GitPlugin
class GitPluginPrivate final : public VcsBasePluginPrivate
@@ -393,8 +391,9 @@ public:
void setupInstantBlame();
void instantBlameOnce();
void instantBlame();
+ void stopInstantBlame();
- void onApplySettings();;
+ void onApplySettings();
CommandLocator *m_commandLocator = nullptr;
@@ -430,6 +429,7 @@ public:
Author m_author;
int m_lastVisitedEditorLine = -1;
QTimer *m_cursorPositionChangedTimer = nullptr;
+ std::unique_ptr<BlameMark> m_blameMark;
QMetaObject::Connection m_blameCursorPosConn;
GitSettingsPage settingPage{&m_settings};
@@ -1436,12 +1436,14 @@ void GitPluginPrivate::setupInstantBlame()
connect(m_cursorPositionChangedTimer, &QTimer::timeout, this, &GitPluginPrivate::instantBlame);
auto setupBlameForEditor = [this](Core::IEditor *editor) {
- if (!editor)
+ if (!editor) {
+ stopInstantBlame();
return;
+ }
if (!GitClient::instance()->settings().instantBlame.value()) {
m_lastVisitedEditorLine = -1;
- m_blameMark.reset();
+ stopInstantBlame();
return;
}
@@ -1471,11 +1473,11 @@ void GitPluginPrivate::setupInstantBlame()
};
connect(&GitClient::instance()->settings().instantBlame,
- &BoolAspect::valueChanged, this, [setupBlameForEditor](bool enabled) {
+ &BoolAspect::valueChanged, this, [this, setupBlameForEditor](bool enabled) {
if (enabled)
setupBlameForEditor(EditorManager::currentEditor());
else
- m_blameMark.reset();
+ stopInstantBlame();
});
connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
@@ -1523,19 +1525,11 @@ void GitPluginPrivate::instantBlameOnce()
const TextEditorWidget *widget = TextEditorWidget::currentTextEditorWidget();
if (!widget)
return;
- auto editorChangedConn = std::make_shared<QMetaObject::Connection>();
connect(EditorManager::instance(), &EditorManager::currentEditorChanged,
- this, [editorChangedConn] {
- disconnect(*editorChangedConn);
- m_blameMark.reset();
- });
+ this, [this] { m_blameMark.reset(); }, Qt::SingleShotConnection);
- auto cursorPosConn = std::make_shared<QMetaObject::Connection>();
- *cursorPosConn = connect(widget, &QPlainTextEdit::cursorPositionChanged,
- this, [cursorPosConn] {
- disconnect(*cursorPosConn);
- m_blameMark.reset();
- });
+ connect(widget, &QPlainTextEdit::cursorPositionChanged,
+ this, [this] { m_blameMark.reset(); }, Qt::SingleShotConnection);
const Utils::FilePath workingDirectory = GitPlugin::currentState().topLevel();
if (workingDirectory.isEmpty())
@@ -1550,6 +1544,8 @@ void GitPluginPrivate::instantBlameOnce()
void GitPluginPrivate::instantBlame()
{
const TextEditorWidget *widget = TextEditorWidget::currentTextEditorWidget();
+ if (!widget)
+ return;
const QTextCursor cursor = widget->textCursor();
const QTextBlock block = cursor.block();
const int line = block.blockNumber() + 1;
@@ -1584,6 +1580,13 @@ void GitPluginPrivate::instantBlame()
});
}
+void GitPluginPrivate::stopInstantBlame()
+{
+ m_blameMark.reset();
+ m_cursorPositionChangedTimer->stop();
+ disconnect(m_blameCursorPosConn);
+}
+
IEditor *GitPluginPrivate::openSubmitEditor(const QString &fileName, const CommitData &cd)
{
IEditor *editor = EditorManager::openEditor(FilePath::fromString(fileName),