Fix field autocomplete in empty chat.

This commit is contained in:
John Preston 2018-06-26 21:15:29 +01:00
parent 35c759c6bc
commit 44c6050bf2
3 changed files with 28 additions and 17 deletions

View File

@ -57,7 +57,10 @@ void FieldAutocomplete::paintEvent(QPaintEvent *e) {
p.fillRect(rect(), st::mentionBg);
}
void FieldAutocomplete::showFiltered(PeerData *peer, QString query, bool addInlineBots) {
void FieldAutocomplete::showFiltered(
not_null<PeerData*> peer,
QString query,
bool addInlineBots) {
_chat = peer->asChat();
_user = peer->asUser();
_channel = peer->asChannel();
@ -105,9 +108,9 @@ void FieldAutocomplete::showStickers(EmojiPtr emoji) {
return;
}
_chat = 0;
_user = 0;
_channel = 0;
_chat = nullptr;
_user = nullptr;
_channel = nullptr;
updateFiltered(resetScroll);
}

View File

@ -32,7 +32,10 @@ public:
FieldAutocomplete(QWidget *parent);
bool clearFilteredBotCommands();
void showFiltered(PeerData *peer, QString query, bool addInlineBots);
void showFiltered(
not_null<PeerData*> peer,
QString query,
bool addInlineBots);
void showStickers(EmojiPtr emoji);
void setBoundings(QRect boundings);

View File

@ -1034,6 +1034,9 @@ void HistoryWidget::onHashtagOrBotCommandInsert(
}
void HistoryWidget::updateInlineBotQuery() {
if (!_history) {
return;
}
const auto query = ParseInlineBotQuery(_field);
if (_inlineBotUsername != query.username) {
_inlineBotUsername = query.username;
@ -1131,20 +1134,22 @@ void HistoryWidget::setReportSpamStatus(DBIPeerReportSpamStatus status) {
}
void HistoryWidget::updateStickersByEmoji() {
int len = 0;
if (!_editMsgId) {
auto &text = _field->getTextWithTags().text;
if (auto emoji = Ui::Emoji::Find(text, &len)) {
if (text.size() > len) {
len = 0;
} else {
_fieldAutocomplete->showStickers(emoji);
if (!_history) {
return;
}
const auto emoji = [&] {
if (!_editMsgId) {
const auto &text = _field->getTextWithTags().text;
auto length = 0;
if (const auto emoji = Ui::Emoji::Find(text, &length)) {
if (text.size() <= length) {
return emoji;
}
}
}
}
if (!len) {
_fieldAutocomplete->showStickers(nullptr);
}
return EmojiPtr(nullptr);
}();
_fieldAutocomplete->showStickers(emoji);
}
void HistoryWidget::onTextChange() {