summaryrefslogtreecommitdiffstats
path: root/framework/src/domain/textdocumenthandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/domain/textdocumenthandler.cpp')
-rw-r--r--framework/src/domain/textdocumenthandler.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/framework/src/domain/textdocumenthandler.cpp b/framework/src/domain/textdocumenthandler.cpp
index f0cde10d..ba0aa98f 100644
--- a/framework/src/domain/textdocumenthandler.cpp
+++ b/framework/src/domain/textdocumenthandler.cpp
@@ -32,7 +32,7 @@ TextDocumentHandler::TextDocumentHandler(QObject *parent)
32{ 32{
33} 33}
34 34
35bool TextDocumentHandler::containsFormatting() 35bool TextDocumentHandler::containsFormatting() const
36{ 36{
37 if (mDocument) { 37 if (mDocument) {
38 for (const auto &format : mDocument->textDocument()->allFormats()) { 38 for (const auto &format : mDocument->textDocument()->allFormats()) {
@@ -62,7 +62,9 @@ bool TextDocumentHandler::containsFormatting()
62 62
63void TextDocumentHandler::resetFormat() 63void TextDocumentHandler::resetFormat()
64{ 64{
65 mDocument->textDocument()->setPlainText(mDocument->textDocument()->toPlainText()); 65 if (mDocument) {
66 mDocument->textDocument()->setPlainText(mDocument->textDocument()->toPlainText());
67 }
66 mCachedTextFormat = {}; 68 mCachedTextFormat = {};
67 reset(); 69 reset();
68} 70}
@@ -76,12 +78,18 @@ void TextDocumentHandler::setDocument(QQuickTextDocument *document)
76{ 78{
77 if (document != mDocument) { 79 if (document != mDocument) {
78 mDocument = document; 80 mDocument = document;
79 connect(mDocument->textDocument(), &QTextDocument::contentsChanged, this, [this] () {
80 emit textChanged();
81 });
82 connect(mDocument->textDocument(), &QTextDocument::contentsChange, this, &TextDocumentHandler::contentsChange); 81 connect(mDocument->textDocument(), &QTextDocument::contentsChange, this, &TextDocumentHandler::contentsChange);
83 emit documentChanged(); 82 emit documentChanged();
83 emit textChanged();
84 }
85}
86
87QString TextDocumentHandler::text() const
88{
89 if (containsFormatting()) {
90 return htmlText();
84 } 91 }
92 return plainText();
85} 93}
86 94
87QString TextDocumentHandler::plainText() const 95QString TextDocumentHandler::plainText() const
@@ -296,6 +304,7 @@ void TextDocumentHandler::contentsChange(int position, int charsRemoved, int cha
296 } 304 }
297 mCachedTextFormat = {}; 305 mCachedTextFormat = {};
298 } 306 }
307 emit textChanged();
299} 308}
300 309
301void TextDocumentHandler::mergeFormatOnWordOrSelection(const QTextCharFormat &format) 310void TextDocumentHandler::mergeFormatOnWordOrSelection(const QTextCharFormat &format)