forked from qt-creator/qt-creator
CompilerExplorer: Fix crash on undo
We need to store the source text document so that when the editor is remove and the user triggers undo/read, the pointer is still valid. Change-Id: I571906db1c4424455172a42d72351cd9ba1e7c03 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -209,14 +209,17 @@ SourceEditorWidget::SourceEditorWidget(const std::shared_ptr<SourceSettings> &se
|
|||||||
|
|
||||||
connect(m_codeEditor, &CodeEditorWidget::gotFocus, this, &SourceEditorWidget::gotFocus);
|
connect(m_codeEditor, &CodeEditorWidget::gotFocus, this, &SourceEditorWidget::gotFocus);
|
||||||
|
|
||||||
TextDocumentPtr document = TextDocumentPtr(new SourceTextDocument(m_sourceSettings, undoStack));
|
auto sourceTextDocument = settings->sourceTextDocument();
|
||||||
|
if (!sourceTextDocument)
|
||||||
|
sourceTextDocument = TextDocumentPtr(new SourceTextDocument(m_sourceSettings, undoStack));
|
||||||
|
settings->setSourceTextDocument(sourceTextDocument);
|
||||||
|
|
||||||
connect(document.get(),
|
connect(sourceTextDocument.get(),
|
||||||
&SourceTextDocument::changed,
|
&SourceTextDocument::changed,
|
||||||
this,
|
this,
|
||||||
&SourceEditorWidget::sourceCodeChanged);
|
&SourceEditorWidget::sourceCodeChanged);
|
||||||
|
|
||||||
m_codeEditor->setTextDocument(document);
|
m_codeEditor->setTextDocument(sourceTextDocument);
|
||||||
m_codeEditor->updateHighlighter();
|
m_codeEditor->updateHighlighter();
|
||||||
|
|
||||||
auto addCompilerButton = new QToolButton;
|
auto addCompilerButton = new QToolButton;
|
||||||
|
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
#include <utils/aspects.h>
|
#include <utils/aspects.h>
|
||||||
|
|
||||||
|
#include <texteditor/textdocument.h>
|
||||||
|
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
|
|
||||||
namespace CompilerExplorer {
|
namespace CompilerExplorer {
|
||||||
@@ -58,6 +60,12 @@ public:
|
|||||||
|
|
||||||
ApiConfigFunction apiConfigFunction() const { return m_apiConfigFunction; }
|
ApiConfigFunction apiConfigFunction() const { return m_apiConfigFunction; }
|
||||||
|
|
||||||
|
TextEditor::TextDocumentPtr sourceTextDocument() const { return m_sourceTextDocument; }
|
||||||
|
void setSourceTextDocument(TextEditor::TextDocumentPtr sourceTextDocument)
|
||||||
|
{
|
||||||
|
m_sourceTextDocument = sourceTextDocument;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Utils::StringSelectionAspect languageId{this};
|
Utils::StringSelectionAspect languageId{this};
|
||||||
Utils::StringAspect source{this};
|
Utils::StringAspect source{this};
|
||||||
@@ -75,6 +83,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
CompilerExplorerSettings *m_parent;
|
CompilerExplorerSettings *m_parent;
|
||||||
ApiConfigFunction m_apiConfigFunction;
|
ApiConfigFunction m_apiConfigFunction;
|
||||||
|
TextEditor::TextDocumentPtr m_sourceTextDocument{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
class CompilerSettings : public Utils::AspectContainer,
|
class CompilerSettings : public Utils::AspectContainer,
|
||||||
|
Reference in New Issue
Block a user