mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-10-18 08:25:30 +02:00
Added simple colorizing of query in found messages.
This commit is contained in:
parent
a28f113105
commit
5c33a2bd5c
5 changed files with 49 additions and 0 deletions
|
@ -1240,6 +1240,7 @@ void InnerWidget::paintEvent(QPaintEvent *e) {
|
|||
auto to = ceilclamp(r.y() + r.height() - skip, _st->height, 0, _previewResults.size());
|
||||
p.translate(0, from * _st->height);
|
||||
if (from < _previewResults.size()) {
|
||||
const auto searchLowerText = _searchState.query.toLower();
|
||||
for (; from < to; ++from) {
|
||||
const auto &result = _previewResults[from];
|
||||
const auto active = isSearchResultActive(result.get(), activeEntry);
|
||||
|
@ -1257,6 +1258,7 @@ void InnerWidget::paintEvent(QPaintEvent *e) {
|
|||
.currentBg = currentBg(),
|
||||
.filter = _filterId,
|
||||
.now = ms,
|
||||
.searchLowerText = QStringView(searchLowerText),
|
||||
.width = fullWidth,
|
||||
.active = active,
|
||||
.selected = selected,
|
||||
|
@ -1284,6 +1286,7 @@ void InnerWidget::paintEvent(QPaintEvent *e) {
|
|||
tr::now,
|
||||
lt_count,
|
||||
_searchedMigratedCount + _searchedCount);
|
||||
const auto searchLowerText = _searchState.query.toLower();
|
||||
p.fillRect(0, 0, fullWidth, st::searchedBarHeight, st::searchedBarBg);
|
||||
p.setFont(st::searchedBarFont);
|
||||
p.setPen(st::searchedBarFg);
|
||||
|
@ -1331,6 +1334,7 @@ void InnerWidget::paintEvent(QPaintEvent *e) {
|
|||
.currentBg = currentBg(),
|
||||
.filter = _filterId,
|
||||
.now = ms,
|
||||
.searchLowerText = QStringView(searchLowerText),
|
||||
.width = fullWidth,
|
||||
.active = active,
|
||||
.selected = selected,
|
||||
|
|
|
@ -1137,6 +1137,7 @@ void RowPainter::Paint(
|
|||
return {};
|
||||
}();
|
||||
previewOptions.ignoreGroup = true;
|
||||
previewOptions.searchLowerText = context.searchLowerText;
|
||||
|
||||
const auto badgesState = context.displayUnreadInfo
|
||||
? entry->chatListBadgesState()
|
||||
|
|
|
@ -64,6 +64,7 @@ struct PaintContext {
|
|||
FilterId filter = 0;
|
||||
float64 topicsExpanded = 0.;
|
||||
crl::time now = 0;
|
||||
QStringView searchLowerText;
|
||||
int width = 0;
|
||||
bool active = false;
|
||||
bool selected = false;
|
||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
#include "history/view/history_view_element.h"
|
||||
#include "history/view/history_view_item_preview.h"
|
||||
#include "main/main_session.h"
|
||||
#include "dialogs/dialogs_three_state_icon.h"
|
||||
|
@ -207,6 +208,47 @@ void MessageView::prepare(
|
|||
}
|
||||
TextUtilities::Trim(preview.text);
|
||||
auto textToCache = DialogsPreviewText(std::move(preview.text));
|
||||
|
||||
if (!options.searchLowerText.isEmpty()) {
|
||||
static constexpr auto kLeftShift = 15;
|
||||
auto minFrom = std::numeric_limits<uint16>::max();
|
||||
|
||||
const auto words = Ui::Text::Words(options.searchLowerText);
|
||||
textToCache.entities.reserve(textToCache.entities.size()
|
||||
+ words.size());
|
||||
|
||||
for (const auto &word : words) {
|
||||
const auto selection = HistoryView::FindSearchQueryHighlight(
|
||||
textToCache.text,
|
||||
word);
|
||||
if (!selection.empty()) {
|
||||
minFrom = std::min(minFrom, selection.from);
|
||||
textToCache.entities.push_back(EntityInText{
|
||||
EntityType::Colorized,
|
||||
selection.from,
|
||||
selection.to - selection.from
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!words.empty() && minFrom != std::numeric_limits<uint16>::max()) {
|
||||
std::sort(
|
||||
textToCache.entities.begin(),
|
||||
textToCache.entities.end(),
|
||||
[](const auto &a, const auto &b) {
|
||||
return a.offset() < b.offset();
|
||||
});
|
||||
|
||||
const auto textSize = textToCache.text.size();
|
||||
minFrom = (minFrom > textSize || minFrom < kLeftShift)
|
||||
? 0
|
||||
: minFrom - kLeftShift;
|
||||
|
||||
textToCache = TextWithEntities(
|
||||
minFrom > 0 ? kQEllipsis : QString())
|
||||
.append(Text::Mid(std::move(textToCache), minFrom));
|
||||
}
|
||||
}
|
||||
_hasPlainLinkAtBegin = !textToCache.entities.empty()
|
||||
&& (textToCache.entities.front().type() == EntityType::Colorized);
|
||||
_textCache.setMarkedText(
|
||||
|
|
|
@ -41,6 +41,7 @@ struct ItemPreview {
|
|||
|
||||
struct ToPreviewOptions {
|
||||
const std::vector<ItemPreviewImage> *existing = nullptr;
|
||||
QStringView searchLowerText;
|
||||
bool hideSender = false;
|
||||
bool hideCaption = false;
|
||||
bool ignoreMessageText = false;
|
||||
|
|
Loading…
Add table
Reference in a new issue