Core: improve highlighting of fuzzy action matches

Split the highlight if it covers the border.

Change-Id: I9177abf18e988b8c2f79ab355a1f17ad3bda4286
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2022-09-26 10:55:09 +02:00
parent e7fb5276af
commit d143f0c2e1

View File

@@ -110,8 +110,8 @@ QList<LocatorFilterEntry> ActionsFilter::matchesFor(QFutureInterface<LocatorFilt
return FilterResult{MatchLevel::Normal, withHighlight(filterEntry)}; return FilterResult{MatchLevel::Normal, withHighlight(filterEntry)};
} }
FuzzyMatcher::HighlightingPositions positions = FuzzyMatcher::highlightingPositions( const FuzzyMatcher::HighlightingPositions positions
allTextMatch); = FuzzyMatcher::highlightingPositions(allTextMatch);
const int positionsCount = positions.starts.count(); const int positionsCount = positions.starts.count();
QTC_ASSERT(positionsCount == positions.lengths.count(), return {}); QTC_ASSERT(positionsCount == positions.lengths.count(), return {});
const int border = first == Highlight::DisplayName ? filterEntry.displayName.length() const int border = first == Highlight::DisplayName ? filterEntry.displayName.length()
@@ -126,8 +126,21 @@ QList<LocatorFilterEntry> ActionsFilter::matchesFor(QFutureInterface<LocatorFilt
type = first == Highlight::DisplayName ? Highlight::ExtraInfo type = first == Highlight::DisplayName ? Highlight::ExtraInfo
: Highlight::DisplayName; : Highlight::DisplayName;
} else if (start + length > border) { } else if (start + length > border) {
// skip this highlight since it starts before and ends after the border const int firstStart = start;
// between the concatenated strings const int firstLength = border - start;
const int secondStart = 0;
const int secondLength = length - firstLength - 1;
if (first == Highlight::DisplayName) {
highlight.startsDisplay.append(firstStart);
highlight.lengthsDisplay.append(firstLength);
highlight.startsExtraInfo.append(secondStart);
highlight.lengthsExtraInfo.append(secondLength);
} else {
highlight.startsExtraInfo.append(firstStart);
highlight.lengthsExtraInfo.append(firstLength);
highlight.startsDisplay.append(secondStart);
highlight.lengthsDisplay.append(secondLength);
}
continue; continue;
} }
if (type == Highlight::DisplayName) { if (type == Highlight::DisplayName) {