Improve application of text formats from buttons.

- If the bar is empty they are now applied as normal
- If there is a selection or the cursor is next to a word it is applied to it.
- If there is no selected text and no word it is applied properly to the next char
This commit is contained in:
James Graham
2026-02-05 19:59:32 +00:00
parent dff6ab66f1
commit c32235ffe3

View File

@@ -481,7 +481,15 @@ void ChatTextItemHelper::mergeTextFormatOnCursor(RichFormat::Format format, QTex
if (!cursor.hasSelection()) {
cursor.select(QTextCursor::WordUnderCursor);
}
cursor.mergeCharFormat(charFormat);
if (!cursor.hasSelection() && isEmpty()) {
cursor.mergeBlockCharFormat(charFormat);
} else if (!cursor.hasSelection()) {
cursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor);
cursor.mergeCharFormat(charFormat);
} else {
cursor.mergeCharFormat(charFormat);
}
Q_EMIT charFormatChanged();
}