From 9f2626385bf9c12a240f5fd17b90304c231fba5e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 8 Oct 2017 22:37:46 +0200 Subject: Clear all formatting when converting to plain text. We used to end up with whatever formatting the current cursor had. Task: https://phabricator.kde.org/T7160 --- framework/qml/TextEditor.qml | 2 +- framework/src/domain/textdocumenthandler.cpp | 11 +++++++++++ framework/src/domain/textdocumenthandler.h | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) (limited to 'framework') diff --git a/framework/qml/TextEditor.qml b/framework/qml/TextEditor.qml index 8a5c2bb9..3ce6b482 100644 --- a/framework/qml/TextEditor.qml +++ b/framework/qml/TextEditor.qml @@ -46,8 +46,8 @@ FocusScope { edit.text = t } else { var t = document.plainText + document.resetFormat() edit.textFormat = Qt.PlainText - edit.font.bold = false edit.text = t } } diff --git a/framework/src/domain/textdocumenthandler.cpp b/framework/src/domain/textdocumenthandler.cpp index 729d39e8..6c2bc323 100644 --- a/framework/src/domain/textdocumenthandler.cpp +++ b/framework/src/domain/textdocumenthandler.cpp @@ -32,6 +32,17 @@ TextDocumentHandler::TextDocumentHandler(QObject *parent) { } +void TextDocumentHandler::resetFormat() +{ + //Clear all formatting from the document. + auto cursor = textCursor(); + cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor); + cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); + cursor.setCharFormat({}); + mCachedTextFormat = {}; + reset(); +} + QQuickTextDocument *TextDocumentHandler::document() const { return mDocument; diff --git a/framework/src/domain/textdocumenthandler.h b/framework/src/domain/textdocumenthandler.h index b8ae5bdb..43781940 100644 --- a/framework/src/domain/textdocumenthandler.h +++ b/framework/src/domain/textdocumenthandler.h @@ -86,6 +86,8 @@ public: int fontSize() const; void setFontSize(int size); + Q_INVOKABLE void resetFormat(); + Q_SIGNALS: void documentChanged(); void cursorPositionChanged(); -- cgit v1.2.3