Allow disabling first-word emoji suggestions.

This commit is contained in:
John Preston 2019-05-27 12:16:14 +02:00
parent a49a96ba33
commit 0eb975e679
3 changed files with 22 additions and 8 deletions

View File

@ -137,7 +137,9 @@ void InitField(
not_null<Ui::InputField*> field) { not_null<Ui::InputField*> field) {
field->setInstantReplaces(Ui::InstantReplaces::Default()); field->setInstantReplaces(Ui::InstantReplaces::Default());
field->setInstantReplacesEnabled(Global::ReplaceEmojiValue()); 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( not_null<Ui::FlatLabel*> CreateWarningLabel(

View File

@ -503,9 +503,11 @@ void SuggestionsWidget::leaveEventHook(QEvent *e) {
SuggestionsController::SuggestionsController( SuggestionsController::SuggestionsController(
not_null<QWidget*> outer, not_null<QWidget*> outer,
not_null<QTextEdit*> field) not_null<QTextEdit*> field,
const Options &options)
: _field(field) : _field(field)
, _showExactTimer([=] { showWithQuery(getEmojiQuery()); }) { , _showExactTimer([=] { showWithQuery(getEmojiQuery()); })
, _options(options) {
_container = base::make_unique_q<InnerDropdown>( _container = base::make_unique_q<InnerDropdown>(
outer, outer,
st::emojiSuggestionsDropdown); st::emojiSuggestionsDropdown);
@ -555,11 +557,13 @@ SuggestionsController::SuggestionsController(
SuggestionsController *SuggestionsController::Init( SuggestionsController *SuggestionsController::Init(
not_null<QWidget*> outer, not_null<QWidget*> outer,
not_null<Ui::InputField*> field) { not_null<Ui::InputField*> field,
const Options &options) {
const auto result = Ui::CreateChild<SuggestionsController>( const auto result = Ui::CreateChild<SuggestionsController>(
field.get(), field.get(),
outer, outer,
field->rawTextEdit()); field->rawTextEdit(),
options);
result->setReplaceCallback([=]( result->setReplaceCallback([=](
int from, int from,
int till, int till,
@ -679,7 +683,8 @@ QString SuggestionsController::getEmojiQuery() {
const auto is = [&](QLatin1String string) { const auto is = [&](QLatin1String string) {
return (text.compare(string, Qt::CaseInsensitive) == 0); return (text.compare(string, Qt::CaseInsensitive) == 0);
}; };
if (!length if (!_options.suggestExactFirstWord
|| !length
|| text[0].isSpace() || text[0].isSpace()
|| (length > modernLimit) || (length > modernLimit)
|| (_queryStartPosition != 0) || (_queryStartPosition != 0)

View File

@ -96,9 +96,14 @@ private:
class SuggestionsController { class SuggestionsController {
public: public:
struct Options {
bool suggestExactFirstWord = true;
};
SuggestionsController( SuggestionsController(
not_null<QWidget*> outer, not_null<QWidget*> outer,
not_null<QTextEdit*> field); not_null<QTextEdit*> field,
const Options &options);
void raise(); void raise();
void setReplaceCallback(Fn<void( void setReplaceCallback(Fn<void(
@ -108,7 +113,8 @@ public:
static SuggestionsController *Init( static SuggestionsController *Init(
not_null<QWidget*> outer, not_null<QWidget*> outer,
not_null<Ui::InputField*> field); not_null<Ui::InputField*> field,
const Options &options = Options());
private: private:
void handleCursorPositionChange(); void handleCursorPositionChange();
@ -139,6 +145,7 @@ private:
base::Timer _showExactTimer; base::Timer _showExactTimer;
bool _keywordsRefreshed = false; bool _keywordsRefreshed = false;
QString _lastShownQuery; QString _lastShownQuery;
Options _options;
rpl::lifetime _lifetime; rpl::lifetime _lifetime;