From 1f31d8032f752c90800255dfcfe3f3137a3beb0d Mon Sep 17 00:00:00 2001 From: John Preston <johnprestonmail@gmail.com> Date: Wed, 8 May 2024 17:16:34 +0400 Subject: [PATCH] Bring chosen font to the top of the box. --- Telegram/SourceFiles/ui/boxes/choose_font_box.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/ui/boxes/choose_font_box.cpp b/Telegram/SourceFiles/ui/boxes/choose_font_box.cpp index 512e8a691..80168ca0f 100644 --- a/Telegram/SourceFiles/ui/boxes/choose_font_box.cpp +++ b/Telegram/SourceFiles/ui/boxes/choose_font_box.cpp @@ -546,15 +546,25 @@ std::vector<Selector::Entry> Selector::FullList(const QString &now) { result.push_back({ .id = family }); } } - if (!ranges::contains(result, now, &Entry::id)) { + auto nowIt = ranges::find(result, now, &Entry::id); + if (nowIt == end(result)) { result.push_back({ .id = now }); + nowIt = end(result) - 1; } for (auto i = begin(result) + 2; i != end(result); ++i) { i->key = TextUtilities::RemoveAccents(i->id).toLower(); i->text = i->id; i->keywords = TextUtilities::PrepareSearchWords(i->id); } - ranges::sort(begin(result) + 2, end(result), std::less<>(), &Entry::key); + auto skip = 2; + if (nowIt - begin(result) >= skip) { + std::swap(result[2], *nowIt); + ++skip; + } + ranges::sort( + begin(result) + skip, end(result), + std::less<>(), + &Entry::key); return result; }