Commit d8537367 authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Fix crashes with temporary files

parent b1a7f281
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include <KTextEditor/Message> #include <KTextEditor/Message>
#include <KTextEditor/View> #include <KTextEditor/View>
GitWidget::GitWidget(KateProject *project, KTextEditor::MainWindow *mainWindow, KateProjectPluginView *pluginView) GitWidget::GitWidget(KateProject *project, KTextEditor::MainWindow *mainWindow, KateProjectPluginView *pluginView)
: m_project(project) : m_project(project)
, m_mainWin(mainWindow) , m_mainWin(mainWindow)
...@@ -272,12 +271,15 @@ void GitWidget::openAtHEAD(const QString &file) ...@@ -272,12 +271,15 @@ void GitWidget::openAtHEAD(const QString &file)
// close temp on document close // close temp on document close
auto clearTemp = [this](KTextEditor::Document *document) { auto clearTemp = [this](KTextEditor::Document *document) {
std::remove_if(m_filesOpenAtHEAD.begin(), m_filesOpenAtHEAD.end(), [document](const GitWidget::TempFileViewPair &tf) { m_filesOpenAtHEAD.erase(std::remove_if(m_filesOpenAtHEAD.begin(),
if (tf.second->document() == document) { m_filesOpenAtHEAD.end(),
return true; [document](const GitWidget::TempFileViewPair &tf) {
} if (tf.second && tf.second->document() == document) {
return false; return true;
}); }
return false;
}),
m_filesOpenAtHEAD.end());
}; };
connect(v->document(), &KTextEditor::Document::aboutToClose, this, clearTemp); connect(v->document(), &KTextEditor::Document::aboutToClose, this, clearTemp);
} }
...@@ -328,12 +330,15 @@ void GitWidget::showDiff(const QString &file, bool staged) ...@@ -328,12 +330,15 @@ void GitWidget::showDiff(const QString &file, bool staged)
// close temp on document close // close temp on document close
auto clearTemp = [this](KTextEditor::Document *document) { auto clearTemp = [this](KTextEditor::Document *document) {
std::remove_if(m_filesOpenAtHEAD.begin(), m_filesOpenAtHEAD.end(), [document](const GitWidget::TempFileViewPair &tf) { m_filesOpenAtHEAD.erase(std::remove_if(m_filesOpenAtHEAD.begin(),
if (tf.second->document() == document) { m_filesOpenAtHEAD.end(),
return true; [document](const GitWidget::TempFileViewPair &tf) {
} if (tf.second && tf.second->document() == document) {
return false; return true;
}); }
return false;
}),
m_filesOpenAtHEAD.end());
}; };
connect(v->document(), &KTextEditor::Document::aboutToClose, this, clearTemp); connect(v->document(), &KTextEditor::Document::aboutToClose, this, clearTemp);
} }
......
...@@ -468,12 +468,15 @@ void StashDialog::showStash(const QByteArray &index) ...@@ -468,12 +468,15 @@ void StashDialog::showStash(const QByteArray &index)
// close temp on document close // close temp on document close
auto clearTemp = [gitWidget](KTextEditor::Document *document) { auto clearTemp = [gitWidget](KTextEditor::Document *document) {
auto tempFiles = gitWidget->tempFilesVector(); auto tempFiles = gitWidget->tempFilesVector();
std::remove_if(tempFiles->begin(), tempFiles->end(), [document](const GitWidget::TempFileViewPair &tf) { tempFiles->erase(std::remove_if(tempFiles->begin(),
if (tf.second->document() == document) { tempFiles->end(),
return true; [document](const GitWidget::TempFileViewPair &tf) {
} if (tf.second->document() == document) {
return false; return true;
}); }
return false;
}),
tempFiles->end());
}; };
connect(v->document(), &KTextEditor::Document::aboutToClose, gitWidget, clearTemp); connect(v->document(), &KTextEditor::Document::aboutToClose, gitWidget, clearTemp);
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment