Commit b0b893ac authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Fixed null-pointer deref in copy/paste.

parent 2e7ddfb9
......@@ -326,7 +326,7 @@ QList<RewriterView::Error> DesignDocumentController::loadMaster(QPlainTextEdit *
connect(edit, SIGNAL(modificationChanged(bool)),
this, SIGNAL(dirtyStateChanged(bool)));
m_d->textModifier = new BaseTextEditModifier(m_d->textEdit.data());
m_d->textModifier = new BaseTextEditModifier(dynamic_cast<TextEditor::BaseTextEditor*>(m_d->textEdit.data()));
m_d->componentTextModifier = 0;
......
......@@ -31,6 +31,7 @@
#include <rewriterview.h>
#include <basetexteditmodifier.h>
#include <metainfo.h>
#include <plaintexteditmodifier.h>
#include <QApplication>
#include <QPlainTextEdit>
......@@ -102,7 +103,7 @@ QString DesignDocumentControllerView::toText() const
outputModel->setMetaInfo(model()->metaInfo());
QPlainTextEdit textEdit;
textEdit.setPlainText("import Qt 4.6; Item {}");
BaseTextEditModifier modifier(&textEdit);
NotIndentingTextEditModifier modifier(&textEdit);
QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, 0));
rewriterView->setTextModifier(&modifier);
......@@ -126,7 +127,7 @@ void DesignDocumentControllerView::fromText(QString text)
QPlainTextEdit textEdit;
QString imports("import Qt 4.6;\n");
textEdit.setPlainText(imports + text);
BaseTextEditModifier modifier(&textEdit);
NotIndentingTextEditModifier modifier(&textEdit);
QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, 0));
rewriterView->setTextModifier(&modifier);
......
......@@ -34,12 +34,14 @@
#include "corelib_global.h"
#include "plaintexteditmodifier.h"
#include <texteditor/basetexteditor.h>
namespace QmlDesigner {
class CORESHARED_EXPORT BaseTextEditModifier: public PlainTextEditModifier
{
public:
BaseTextEditModifier(QPlainTextEdit *textEdit);
BaseTextEditModifier(TextEditor::BaseTextEditor *textEdit);
virtual void indent(int offset, int length);
......
......@@ -66,6 +66,8 @@ public:
virtual void move(const MoveInfo &moveInfo);
virtual void indent(int offset, int length) = 0;
virtual int indentDepth() const = 0;
virtual void startGroup();
virtual void flushGroup();
virtual void commitGroup();
......@@ -91,6 +93,20 @@ private:
bool m_ongoingTextChange;
};
class CORESHARED_EXPORT NotIndentingTextEditModifier: public PlainTextEditModifier
{
public:
NotIndentingTextEditModifier(QPlainTextEdit *textEdit)
: PlainTextEditModifier(textEdit)
{}
virtual void indent(int /*offset*/, int /*length*/)
{}
virtual int indentDepth() const
{ return 0; }
};
}
#endif // PLAINTEXTEDITMODIFIER_H
......@@ -29,12 +29,11 @@
#include "basetexteditmodifier.h"
#include <texteditor/basetexteditor.h>
#include <texteditor/tabsettings.h>
using namespace QmlDesigner;
BaseTextEditModifier::BaseTextEditModifier(QPlainTextEdit *textEdit):
BaseTextEditModifier::BaseTextEditModifier(TextEditor::BaseTextEditor *textEdit):
PlainTextEditModifier(textEdit)
{
}
......@@ -44,9 +43,7 @@ void BaseTextEditModifier::indent(int offset, int length)
if (length == 0 || offset < 0 || offset + length >= text().length())
return;
// qDebug() << "PlainTextEditModifier::indent(" << offset << "," << length << ")";
if (TextEditor::BaseTextEditor *bte = dynamic_cast<TextEditor::BaseTextEditor*>(plainTextEdit())) {
// qDebug() << "**** Doing indentation";
// find the applicable block:
QTextDocument *doc = bte->document();
QTextCursor tc(doc);
......@@ -55,8 +52,6 @@ void BaseTextEditModifier::indent(int offset, int length)
tc.setPosition(offset + length, QTextCursor::KeepAnchor);
bte->indentInsertedText(tc);
tc.endEditBlock();
} else {
// qDebug() << "**** Skipping indentation";
}
}
......@@ -65,7 +60,6 @@ int BaseTextEditModifier::indentDepth() const
if (TextEditor::BaseTextEditor *bte = dynamic_cast<TextEditor::BaseTextEditor*>(plainTextEdit())) {
return bte->tabSettings().m_indentSize;
} else {
Q_ASSERT(false && "BaseTextEditModifier does not have a BaseTextEditor");
return 0;
}
}
......@@ -46,6 +46,8 @@ PlainTextEditModifier::PlainTextEditModifier(QPlainTextEdit *textEdit):
m_pendingChangeSignal(false),
m_ongoingTextChange(false)
{
Q_ASSERT(textEdit);
connect(m_textEdit, SIGNAL(textChanged()),
this, SLOT(textEditChanged()));
}
......
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