Have ChatDocumentHandler update ChatBarCache text

Have ChatDocumentHandler update ChatBarCache text so all text operations in the ChatBar go through it
This commit is contained in:
James Graham
2025-08-11 19:33:58 +01:00
parent bc82ceeb5f
commit 9ed5224470
2 changed files with 13 additions and 4 deletions

View File

@@ -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