mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Replace many same emoji at once.
This commit is contained in:
parent
f63984c9e3
commit
a098abefd7
2 changed files with 22 additions and 7 deletions
|
@ -756,6 +756,11 @@ void SuggestionsController::handleTextChange() {
|
|||
const auto query = getEmojiQuery();
|
||||
if (v::is<EmojiPtr>(query)) {
|
||||
showWithQuery(query);
|
||||
InvokeQueued(_container, [=] {
|
||||
if (_shown) {
|
||||
updateGeometry();
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
const auto text = v::get<QString>(query);
|
||||
|
@ -811,11 +816,13 @@ SuggestionsQuery SuggestionsController::getEmojiQuery() {
|
|||
const auto imageName = format.toImageFormat().name();
|
||||
if (const auto emoji = Emoji::FromUrl(imageName)) {
|
||||
_queryStartPosition = position - 1;
|
||||
_emojiQueryLength = (position - from);
|
||||
return emoji;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
_queryStartPosition = from;
|
||||
_emojiQueryLength = 0;
|
||||
return fragment.text();
|
||||
}
|
||||
return QString();
|
||||
|
@ -866,16 +873,23 @@ SuggestionsQuery SuggestionsController::getEmojiQuery() {
|
|||
void SuggestionsController::replaceCurrent(
|
||||
const QString &replacement,
|
||||
const QString &customEmojiData) {
|
||||
const auto cursor = _field->textCursor();
|
||||
const auto position = cursor.position();
|
||||
const auto suggestion = getEmojiQuery();
|
||||
const auto length = v::is<EmojiPtr>(suggestion)
|
||||
? 1
|
||||
: v::get<QString>(suggestion).size();
|
||||
if (!length) {
|
||||
if (v::is<EmojiPtr>(suggestion)) {
|
||||
const auto weak = Ui::MakeWeak(_container.get());
|
||||
const auto count = std::max(_emojiQueryLength, 1);
|
||||
for (auto i = 0; i != count; ++i) {
|
||||
const auto start = position - count + i;
|
||||
_replaceCallback(start, start + 1, replacement, customEmojiData);
|
||||
if (!weak) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (v::get<QString>(suggestion).isEmpty()) {
|
||||
showWithQuery(QString());
|
||||
} else {
|
||||
const auto cursor = _field->textCursor();
|
||||
const auto position = cursor.position();
|
||||
const auto from = position - length;
|
||||
const auto from = position - v::get<QString>(suggestion).size();
|
||||
_replaceCallback(from, position, replacement, customEmojiData);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,6 +192,7 @@ private:
|
|||
bool _shown = false;
|
||||
bool _forceHidden = false;
|
||||
int _queryStartPosition = 0;
|
||||
int _emojiQueryLength = 0;
|
||||
bool _ignoreCursorPositionChange = false;
|
||||
bool _textChangeAfterKeyPress = false;
|
||||
QPointer<QTextEdit> _field;
|
||||
|
|
Loading…
Add table
Reference in a new issue