diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.cpp b/Telegram/SourceFiles/ui/widgets/input_fields.cpp index c2394679f..bc3ef250f 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.cpp +++ b/Telegram/SourceFiles/ui/widgets/input_fields.cpp @@ -696,6 +696,9 @@ protected: void dropEvent(QDropEvent *e) override { return outer()->dropEventInner(e); } + void inputMethodEvent(QInputMethodEvent *e) override { + return outer()->inputMethodEventInner(e); + } bool canInsertFromMimeData(const QMimeData *source) const override { return outer()->canInsertFromMimeDataInner(source); @@ -2067,9 +2070,7 @@ void InputField::setPlaceholderHidden(bool forcePlaceholderHidden) { void InputField::startPlaceholderAnimation() { const auto textLength = [&] { - const auto layout = textCursor().block().layout(); - return getTextWithTags().text.size() - + (layout ? layout->preeditAreaText().size() : 0); + return getTextWithTags().text.size() + _lastPreEditText.size(); }; const auto placeholderShifted = _forcePlaceholderHidden || (_focused && _st.placeholderScale > 0.) @@ -2324,6 +2325,19 @@ bool InputField::handleMarkdownKey(QKeyEvent *e) { return true; } +void InputField::inputMethodEventInner(QInputMethodEvent *e) { + const auto preedit = e->preeditString(); + if (_lastPreEditText != preedit) { + _lastPreEditText = preedit; + startPlaceholderAnimation(); + } + const auto text = e->commitString(); + _inner->QTextEdit::inputMethodEvent(e); + if (!processMarkdownReplaces(text)) { + processInstantReplaces(text); + } +} + const InstantReplaces &InputField::instantReplaces() const { return _mutableInstantReplaces; } @@ -2378,6 +2392,13 @@ void InputField::processInstantReplaces(const QString &appended) { return; } const auto position = textCursor().position(); + for (const auto &tag : _textAreaPossibleTags) { + if (tag.start < position + && tag.start + tag.length >= position + && (tag.tag == kTagCode || tag.tag == kTagPre)) { + return; + } + } const auto typed = getTextWithTagsPart( std::max(position - replaces.maxLength, 0), position - 1).text; diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.h b/Telegram/SourceFiles/ui/widgets/input_fields.h index cf7f1a009..e6287b43a 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.h +++ b/Telegram/SourceFiles/ui/widgets/input_fields.h @@ -317,6 +317,7 @@ private: void keyPressEventInner(QKeyEvent *e); void contextMenuEventInner(QContextMenuEvent *e); void dropEventInner(QDropEvent *e); + void inputMethodEventInner(QInputMethodEvent *e); QMimeData *createMimeDataFromSelectionInner() const; bool canInsertFromMimeDataInner(const QMimeData *source) const; @@ -371,6 +372,7 @@ private: TextWithTags _lastTextWithTags; std::vector _textAreaPossibleTags; + QString _lastPreEditText; // Tags list which we should apply while setText() call or insert from mime data. TagList _insertedTags;