Fix link insertion
This commit is contained in:
@@ -213,10 +213,16 @@ void ChatDocumentHandler::setTextItem(QQuickItem *textItem)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cursor.setPosition(position);
|
cursor.setPosition(position);
|
||||||
cursor.select(QTextCursor::WordUnderCursor);
|
cursor.movePosition(QTextCursor::NextWord, QTextCursor::KeepAnchor);
|
||||||
if (!cursor.selectedText().isEmpty()) {
|
if (!cursor.selectedText().isEmpty()) {
|
||||||
cursor.mergeCharFormat(m_pendingFormat);
|
if (m_pendingFormat) {
|
||||||
m_pendingFormat = {};
|
cursor.mergeCharFormat(*m_pendingFormat);
|
||||||
|
m_pendingFormat = std::nullopt;
|
||||||
|
}
|
||||||
|
if (m_pendingOverrideFormat) {
|
||||||
|
cursor.setCharFormat(*m_pendingOverrideFormat);
|
||||||
|
m_pendingOverrideFormat = std::nullopt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
initializeChars();
|
initializeChars();
|
||||||
@@ -866,7 +872,8 @@ void ChatDocumentHandler::updateLink(const QString &linkUrl, const QString &link
|
|||||||
cursor.select(QTextCursor::WordUnderCursor);
|
cursor.select(QTextCursor::WordUnderCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCharFormat format = cursor.charFormat();
|
const auto originalFormat = cursor.charFormat();
|
||||||
|
auto format = cursor.charFormat();
|
||||||
// Save original format to create an extra space with the existing char
|
// Save original format to create an extra space with the existing char
|
||||||
// format for the block
|
// format for the block
|
||||||
if (!linkUrl.isEmpty()) {
|
if (!linkUrl.isEmpty()) {
|
||||||
@@ -902,8 +909,9 @@ void ChatDocumentHandler::updateLink(const QString &linkUrl, const QString &link
|
|||||||
_linkText = linkUrl;
|
_linkText = linkUrl;
|
||||||
}
|
}
|
||||||
cursor.insertText(_linkText, format);
|
cursor.insertText(_linkText, format);
|
||||||
|
|
||||||
cursor.endEditBlock();
|
cursor.endEditBlock();
|
||||||
|
|
||||||
|
m_pendingOverrideFormat = originalFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor ChatDocumentHandler::linkColor()
|
QColor ChatDocumentHandler::linkColor()
|
||||||
|
|||||||
@@ -243,7 +243,8 @@ private:
|
|||||||
void setListFormat(RichFormat::Format format);
|
void setListFormat(RichFormat::Format format);
|
||||||
|
|
||||||
QPointer<ChatMarkdownHelper> m_markdownHelper;
|
QPointer<ChatMarkdownHelper> m_markdownHelper;
|
||||||
QTextCharFormat m_pendingFormat = {};
|
std::optional<QTextCharFormat> m_pendingFormat = std::nullopt;
|
||||||
|
std::optional<QTextCharFormat> m_pendingOverrideFormat = std::nullopt;
|
||||||
|
|
||||||
SyntaxHighlighter *m_highlighter = nullptr;
|
SyntaxHighlighter *m_highlighter = nullptr;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user