mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-20 23:27:23 +00:00
Allow disabling first-word emoji suggestions.
This commit is contained in:
parent
a49a96ba33
commit
0eb975e679
@ -137,7 +137,9 @@ void InitField(
|
||||
not_null<Ui::InputField*> field) {
|
||||
field->setInstantReplaces(Ui::InstantReplaces::Default());
|
||||
field->setInstantReplacesEnabled(Global::ReplaceEmojiValue());
|
||||
Ui::Emoji::SuggestionsController::Init(container, field);
|
||||
auto options = Ui::Emoji::SuggestionsController::Options();
|
||||
options.suggestExactFirstWord = false;
|
||||
Ui::Emoji::SuggestionsController::Init(container, field, options);
|
||||
}
|
||||
|
||||
not_null<Ui::FlatLabel*> CreateWarningLabel(
|
||||
|
@ -503,9 +503,11 @@ void SuggestionsWidget::leaveEventHook(QEvent *e) {
|
||||
|
||||
SuggestionsController::SuggestionsController(
|
||||
not_null<QWidget*> outer,
|
||||
not_null<QTextEdit*> field)
|
||||
not_null<QTextEdit*> field,
|
||||
const Options &options)
|
||||
: _field(field)
|
||||
, _showExactTimer([=] { showWithQuery(getEmojiQuery()); }) {
|
||||
, _showExactTimer([=] { showWithQuery(getEmojiQuery()); })
|
||||
, _options(options) {
|
||||
_container = base::make_unique_q<InnerDropdown>(
|
||||
outer,
|
||||
st::emojiSuggestionsDropdown);
|
||||
@ -555,11 +557,13 @@ SuggestionsController::SuggestionsController(
|
||||
|
||||
SuggestionsController *SuggestionsController::Init(
|
||||
not_null<QWidget*> outer,
|
||||
not_null<Ui::InputField*> field) {
|
||||
not_null<Ui::InputField*> field,
|
||||
const Options &options) {
|
||||
const auto result = Ui::CreateChild<SuggestionsController>(
|
||||
field.get(),
|
||||
outer,
|
||||
field->rawTextEdit());
|
||||
field->rawTextEdit(),
|
||||
options);
|
||||
result->setReplaceCallback([=](
|
||||
int from,
|
||||
int till,
|
||||
@ -679,7 +683,8 @@ QString SuggestionsController::getEmojiQuery() {
|
||||
const auto is = [&](QLatin1String string) {
|
||||
return (text.compare(string, Qt::CaseInsensitive) == 0);
|
||||
};
|
||||
if (!length
|
||||
if (!_options.suggestExactFirstWord
|
||||
|| !length
|
||||
|| text[0].isSpace()
|
||||
|| (length > modernLimit)
|
||||
|| (_queryStartPosition != 0)
|
||||
|
@ -96,9 +96,14 @@ private:
|
||||
|
||||
class SuggestionsController {
|
||||
public:
|
||||
struct Options {
|
||||
bool suggestExactFirstWord = true;
|
||||
};
|
||||
|
||||
SuggestionsController(
|
||||
not_null<QWidget*> outer,
|
||||
not_null<QTextEdit*> field);
|
||||
not_null<QTextEdit*> field,
|
||||
const Options &options);
|
||||
|
||||
void raise();
|
||||
void setReplaceCallback(Fn<void(
|
||||
@ -108,7 +113,8 @@ public:
|
||||
|
||||
static SuggestionsController *Init(
|
||||
not_null<QWidget*> outer,
|
||||
not_null<Ui::InputField*> field);
|
||||
not_null<Ui::InputField*> field,
|
||||
const Options &options = Options());
|
||||
|
||||
private:
|
||||
void handleCursorPositionChange();
|
||||
@ -139,6 +145,7 @@ private:
|
||||
base::Timer _showExactTimer;
|
||||
bool _keywordsRefreshed = false;
|
||||
QString _lastShownQuery;
|
||||
Options _options;
|
||||
|
||||
rpl::lifetime _lifetime;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user