Commit 8f22c537 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Clean undo class when text is modified

parent dfe9cba8
......@@ -72,6 +72,7 @@ public:
}
};
UndoHtmlVersion undoHtmlVersion;
bool blockClearUndoHtmlVersion = false;
};
RichTextComposer::RichTextComposer(QWidget *parent)
......@@ -79,6 +80,13 @@ RichTextComposer::RichTextComposer(QWidget *parent)
, d(new RichTextComposerPrivate(this))
{
setAcceptRichText(false);
connect(this, &RichTextComposer::textChanged, this, [this]() {
if (!d->blockClearUndoHtmlVersion && d->undoHtmlVersion.isValid() && (d->mode == RichTextComposer::Plain)) {
if (toPlainText() != d->undoHtmlVersion.plainText) {
d->undoHtmlVersion.clear();
}
}
});
}
RichTextComposer::~RichTextComposer()
......@@ -281,11 +289,13 @@ void RichTextComposer::switchToPlainText()
{
if (d->mode == RichTextComposer::Rich) {
d->mode = RichTextComposer::Plain;
d->blockClearUndoHtmlVersion = true;
d->undoHtmlVersion.originalHtml = toHtml();
// TODO: Warn the user about this?
insertPlainTextImplementation();
setAcceptRichText(false);
d->undoHtmlVersion.plainText = toPlainText();
d->blockClearUndoHtmlVersion = false;
Q_EMIT textModeChanged(d->mode);
}
}
......
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