diff --git a/src/chatbar/ChatBar.qml b/src/chatbar/ChatBar.qml index f876f9a0f..d99f06494 100644 --- a/src/chatbar/ChatBar.qml +++ b/src/chatbar/ChatBar.qml @@ -253,6 +253,7 @@ QQC2.Control { placeholderText: root.currentRoom.usesEncryption ? i18n("Send an encrypted message…") : root.currentRoom.mainCache.attachmentPath.length > 0 ? i18n("Set an attachment caption…") : i18n("Send a message…") verticalAlignment: TextEdit.AlignVCenter wrapMode: TextEdit.Wrap + textFormat: TextEdit.MarkdownText Accessible.description: placeholderText @@ -269,7 +270,6 @@ QQC2.Control { root.currentRoom.sendTypingNotification(textExists); textExists ? repeatTimer.start() : repeatTimer.stop(); } - _private.chatBarCache.text = text; } onSelectedTextChanged: { if (selectedText.length > 0) { diff --git a/src/libneochat/chatdocumenthandler.cpp b/src/libneochat/chatdocumenthandler.cpp index 8f7317e53..43d4684a7 100644 --- a/src/libneochat/chatdocumenthandler.cpp +++ b/src/libneochat/chatdocumenthandler.cpp @@ -185,6 +185,15 @@ void ChatDocumentHandler::setTextItem(QQuickItem *textItem) m_highlighter->setDocument(document()); if (m_textItem) { connect(m_textItem, SIGNAL(cursorPositionChanged()), this, SLOT(updateCompletion())); + if (document()) { + connect(document(), &QTextDocument::contentsChanged, this, [this]() { + if (m_room) { + m_room->cacheForType(m_type)->setText(getText()); + int start = completionStartIndex(); + m_completionModel->setText(getText().mid(start, cursorPosition() - start), getText().mid(start)); + } + }); + } } Q_EMIT textItemChanged(); @@ -317,11 +326,11 @@ CompletionModel *ChatDocumentHandler::completionModel() const QString ChatDocumentHandler::getText() const { - if (!m_room || m_type == ChatBarType::None) { - qCWarning(ChatDocumentHandling) << "getText called with no ChatBarCache available. ChatBarType: " << m_type << " Room: " << m_room; + if (!document()) { + qCWarning(ChatDocumentHandling) << "getText called with no QQuickTextDocument available."; return {}; } - return m_room->cacheForType(m_type)->text(); + return document()->toRawText(); } void ChatDocumentHandler::pushMention(const Mention mention) const