diff --git a/ui/widgets/input_fields.cpp b/ui/widgets/input_fields.cpp index abadd34..65934e7 100644 --- a/ui/widgets/input_fields.cpp +++ b/ui/widgets/input_fields.cpp @@ -2085,6 +2085,9 @@ void InputField::processFormatting(int insertPosition, int insertEnd) { action.intervalStart = fragmentPosition + (ch - textStart); action.intervalEnd = action.intervalStart + emojiLength; } + if (emojiLength > 1) { + _emojiSurrogateAmount += emojiLength - 1; + } break; } @@ -2220,7 +2223,9 @@ void InputField::onDocumentContentsChange( _correcting = false; QTextCursor(document->docHandle(), 0).endEditBlock(); handleContentsChanged(); - _documentContentsChanges.fire({position, charsRemoved, charsAdded}); + const auto added = charsAdded - _emojiSurrogateAmount; + _documentContentsChanges.fire({position, charsRemoved, added}); + _emojiSurrogateAmount = 0; }); chopByMaxLength(insertPosition, insertLength); diff --git a/ui/widgets/input_fields.h b/ui/widgets/input_fields.h index f85cb9a..4fd9dbc 100644 --- a/ui/widgets/input_fields.h +++ b/ui/widgets/input_fields.h @@ -482,6 +482,10 @@ private: int _realInsertPosition = -1; int _realCharsAdded = 0; + // Calculate the amount of emoji extra chars + // before _documentContentsChanges fire. + int _emojiSurrogateAmount = 0; + std::unique_ptr _tagMimeProcessor; SubmitSettings _submitSettings = SubmitSettings::Enter;