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 @@
#include <KTextEditor/Message>
#include <KTextEditor/View>
GitWidget::GitWidget(KateProject *project, KTextEditor::MainWindow *mainWindow, KateProjectPluginView *pluginView)
: m_project(project)
, m_mainWin(mainWindow)
......@@ -272,12 +271,15 @@ void GitWidget::openAtHEAD(const QString &file)
// close temp on document close
auto clearTemp = [this](KTextEditor::Document *document) {
std::remove_if(m_filesOpenAtHEAD.begin(), m_filesOpenAtHEAD.end(), [document](const GitWidget::TempFileViewPair &tf) {
if (tf.second->document() == document) {
return true;
}
return false;
});
m_filesOpenAtHEAD.erase(std::remove_if(m_filesOpenAtHEAD.begin(),
m_filesOpenAtHEAD.end(),
[document](const GitWidget::TempFileViewPair &tf) {
if (tf.second && tf.second->document() == document) {
return true;
}
return false;
}),
m_filesOpenAtHEAD.end());
};
connect(v->document(), &KTextEditor::Document::aboutToClose, this, clearTemp);
}
......@@ -328,12 +330,15 @@ void GitWidget::showDiff(const QString &file, bool staged)
// close temp on document close
auto clearTemp = [this](KTextEditor::Document *document) {
std::remove_if(m_filesOpenAtHEAD.begin(), m_filesOpenAtHEAD.end(), [document](const GitWidget::TempFileViewPair &tf) {
if (tf.second->document() == document) {
return true;
}
return false;
});
m_filesOpenAtHEAD.erase(std::remove_if(m_filesOpenAtHEAD.begin(),
m_filesOpenAtHEAD.end(),
[document](const GitWidget::TempFileViewPair &tf) {
if (tf.second && tf.second->document() == document) {
return true;
}
return false;
}),
m_filesOpenAtHEAD.end());
};
connect(v->document(), &KTextEditor::Document::aboutToClose, this, clearTemp);
}
......
......@@ -468,12 +468,15 @@ void StashDialog::showStash(const QByteArray &index)
// close temp on document close
auto clearTemp = [gitWidget](KTextEditor::Document *document) {
auto tempFiles = gitWidget->tempFilesVector();
std::remove_if(tempFiles->begin(), tempFiles->end(), [document](const GitWidget::TempFileViewPair &tf) {
if (tf.second->document() == document) {
return true;
}
return false;
});
tempFiles->erase(std::remove_if(tempFiles->begin(),
tempFiles->end(),
[document](const GitWidget::TempFileViewPair &tf) {
if (tf.second->document() == document) {
return true;
}
return false;
}),
tempFiles->end());
};
connect(v->document(), &KTextEditor::Document::aboutToClose, gitWidget, clearTemp);
}
......
Markdown is supported
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