mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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();
|
const auto query = getEmojiQuery();
|
||||||
if (v::is<EmojiPtr>(query)) {
|
if (v::is<EmojiPtr>(query)) {
|
||||||
showWithQuery(query);
|
showWithQuery(query);
|
||||||
|
InvokeQueued(_container, [=] {
|
||||||
|
if (_shown) {
|
||||||
|
updateGeometry();
|
||||||
|
}
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto text = v::get<QString>(query);
|
const auto text = v::get<QString>(query);
|
||||||
|
@ -811,11 +816,13 @@ SuggestionsQuery SuggestionsController::getEmojiQuery() {
|
||||||
const auto imageName = format.toImageFormat().name();
|
const auto imageName = format.toImageFormat().name();
|
||||||
if (const auto emoji = Emoji::FromUrl(imageName)) {
|
if (const auto emoji = Emoji::FromUrl(imageName)) {
|
||||||
_queryStartPosition = position - 1;
|
_queryStartPosition = position - 1;
|
||||||
|
_emojiQueryLength = (position - from);
|
||||||
return emoji;
|
return emoji;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
_queryStartPosition = from;
|
_queryStartPosition = from;
|
||||||
|
_emojiQueryLength = 0;
|
||||||
return fragment.text();
|
return fragment.text();
|
||||||
}
|
}
|
||||||
return QString();
|
return QString();
|
||||||
|
@ -866,16 +873,23 @@ SuggestionsQuery SuggestionsController::getEmojiQuery() {
|
||||||
void SuggestionsController::replaceCurrent(
|
void SuggestionsController::replaceCurrent(
|
||||||
const QString &replacement,
|
const QString &replacement,
|
||||||
const QString &customEmojiData) {
|
const QString &customEmojiData) {
|
||||||
|
const auto cursor = _field->textCursor();
|
||||||
|
const auto position = cursor.position();
|
||||||
const auto suggestion = getEmojiQuery();
|
const auto suggestion = getEmojiQuery();
|
||||||
const auto length = v::is<EmojiPtr>(suggestion)
|
if (v::is<EmojiPtr>(suggestion)) {
|
||||||
? 1
|
const auto weak = Ui::MakeWeak(_container.get());
|
||||||
: v::get<QString>(suggestion).size();
|
const auto count = std::max(_emojiQueryLength, 1);
|
||||||
if (!length) {
|
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());
|
showWithQuery(QString());
|
||||||
} else {
|
} else {
|
||||||
const auto cursor = _field->textCursor();
|
const auto from = position - v::get<QString>(suggestion).size();
|
||||||
const auto position = cursor.position();
|
|
||||||
const auto from = position - length;
|
|
||||||
_replaceCallback(from, position, replacement, customEmojiData);
|
_replaceCallback(from, position, replacement, customEmojiData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,6 +192,7 @@ private:
|
||||||
bool _shown = false;
|
bool _shown = false;
|
||||||
bool _forceHidden = false;
|
bool _forceHidden = false;
|
||||||
int _queryStartPosition = 0;
|
int _queryStartPosition = 0;
|
||||||
|
int _emojiQueryLength = 0;
|
||||||
bool _ignoreCursorPositionChange = false;
|
bool _ignoreCursorPositionChange = false;
|
||||||
bool _textChangeAfterKeyPress = false;
|
bool _textChangeAfterKeyPress = false;
|
||||||
QPointer<QTextEdit> _field;
|
QPointer<QTextEdit> _field;
|
||||||
|
|
Loading…
Add table
Reference in a new issue