Forward input method event from Dialogs::Widget to search field

This commit is contained in:
Ilya Fedin 2024-05-17 03:24:20 +04:00 committed by John Preston
parent 98b58c1168
commit 65b62485be
2 changed files with 31 additions and 0 deletions

View file

@ -82,6 +82,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/qt/qt_common_adapters.h" #include "base/qt/qt_common_adapters.h"
#include <QtCore/QMimeData> #include <QtCore/QMimeData>
#include <QtGui/QTextBlock>
#include <QtWidgets/QScrollBar> #include <QtWidgets/QScrollBar>
#include <QtWidgets/QTextEdit> #include <QtWidgets/QTextEdit>
@ -239,6 +240,8 @@ Widget::Widget(
: nullptr) : nullptr)
, _searchTimer([=] { searchMessages(); }) , _searchTimer([=] { searchMessages(); })
, _singleMessageSearch(&controller->session()) { , _singleMessageSearch(&controller->session()) {
setAttribute(Qt::WA_InputMethodEnabled);
const auto makeChildListShown = [](PeerId peerId, float64 shown) { const auto makeChildListShown = [](PeerId peerId, float64 shown) {
return InnerWidget::ChildListShown{ peerId, shown }; return InnerWidget::ChildListShown{ peerId, shown };
}; };
@ -3298,6 +3301,31 @@ void Widget::keyPressEvent(QKeyEvent *e) {
} }
} }
void Widget::inputMethodEvent(QInputMethodEvent *e) {
const auto cursor = _search->rawTextEdit()->textCursor();
bool isGettingInput = !e->commitString().isEmpty()
|| e->preeditString() != cursor.block().layout()->preeditAreaText()
|| e->replacementLength() > 0;
if (!isGettingInput || _postponeProcessSearchFocusChange) {
Window::AbstractSectionWidget::inputMethodEvent(e);
return;
}
// This delay in search focus processing allows us not to create
// _suggestions in case the event inserts some non-whitespace search
// query while still show _suggestions animated, if it is a space.
_postponeProcessSearchFocusChange = true;
_search->setFocusFast();
QCoreApplication::sendEvent(_search->rawTextEdit(), e);
_postponeProcessSearchFocusChange = false;
processSearchFocusChange();
}
QVariant Widget::inputMethodQuery(Qt::InputMethodQuery query) const {
return _search->rawTextEdit()->inputMethodQuery(query);
}
bool Widget::redirectToSearchPossible() const { bool Widget::redirectToSearchPossible() const {
return !_openedFolder return !_openedFolder
&& !_openedForum && !_openedForum

View file

@ -135,6 +135,8 @@ public:
bool cancelSearch(); bool cancelSearch();
bool cancelSearchByMouseBack(); bool cancelSearchByMouseBack();
QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
~Widget(); ~Widget();
protected: protected:
@ -144,6 +146,7 @@ protected:
void dropEvent(QDropEvent *e) override; void dropEvent(QDropEvent *e) override;
void resizeEvent(QResizeEvent *e) override; void resizeEvent(QResizeEvent *e) override;
void keyPressEvent(QKeyEvent *e) override; void keyPressEvent(QKeyEvent *e) override;
void inputMethodEvent(QInputMethodEvent *e) override;
void paintEvent(QPaintEvent *e) override; void paintEvent(QPaintEvent *e) override;
private: private: