Insert emoji instead of text replacement.

This commit is contained in:
John Preston 2017-07-27 13:22:51 +03:00
parent 80ee40eb18
commit 0517f9f780
2 changed files with 15 additions and 5 deletions

View File

@ -219,9 +219,7 @@ void SuggestionsWidget::keyPressEvent(QKeyEvent *e) {
void SuggestionsWidget::handleKeyEvent(int key) {
if (key == Qt::Key_Enter || key == Qt::Key_Return || key == Qt::Key_Tab) {
if (_selected >= 0 && _selected < _rows.size()) {
triggered.notify(_rows[_selected].replacement(), true);
}
triggerSelectedRow();
return;
}
if ((key != Qt::Key_Up && key != Qt::Key_Down) || _rows.size() < 1) {
@ -333,11 +331,21 @@ void SuggestionsWidget::mouseReleaseEvent(QMouseEvent *e) {
_rows[pressed].ripple()->lastStop();
}
if (pressed == _selected) {
triggered.notify(_rows[_selected].replacement(), true);
triggerRow(_rows[_selected]);
}
}
}
void SuggestionsWidget::triggerSelectedRow() {
if (_selected >= 0 && _selected < _rows.size()) {
triggerRow(_rows[_selected]);
}
}
void SuggestionsWidget::triggerRow(const Row &row) {
triggered.notify(row.emoji()->text(), true);
}
void SuggestionsWidget::enterEventHook(QEvent *e) {
auto mouse = QCursor::pos();
if (!rect().marginsRemoved(QMargins(0, _st->skip, 0, _st->skip)).contains(mapFromGlobal(mouse))) {
@ -454,7 +462,7 @@ void SuggestionsController::replaceCurrent(const QString &replacement) {
_suggestions->showWithQuery(QString());
} else {
cursor.setPosition(cursor.position() - suggestion.size(), QTextCursor::KeepAnchor);
cursor.insertText(replacement + ' ');
cursor.insertText(replacement);
}
auto emojiText = GetSuggestionEmoji(QStringToUTF16(replacement));

View File

@ -62,6 +62,8 @@ private:
int itemTop(int index);
void updateItem(int index);
void updateSelection(QPoint globalPosition);
void triggerSelectedRow();
void triggerRow(const Row &row);
gsl::not_null<const style::Menu*> _st;