mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-24 15:03:47 +00:00
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
58 lines
1.6 KiB
Plaintext
58 lines
1.6 KiB
Plaintext
#import "MWMSearchCell.h"
|
|
#import "SearchResult.h"
|
|
|
|
@interface MWMSearchCell ()
|
|
|
|
@property (weak, nonatomic) IBOutlet UILabel * titleLabel;
|
|
|
|
@end
|
|
|
|
@implementation MWMSearchCell
|
|
|
|
- (void)configureWith:(SearchResult * _Nonnull)result isPartialMatching:(BOOL)isPartialMatching {
|
|
NSString * title = result.titleText;
|
|
|
|
if (title.length == 0)
|
|
{
|
|
self.titleLabel.text = @"";
|
|
return;
|
|
}
|
|
|
|
NSDictionary * selectedTitleAttributes = [self selectedTitleAttributes];
|
|
NSDictionary * unselectedTitleAttributes = [self unselectedTitleAttributes];
|
|
if (!selectedTitleAttributes || !unselectedTitleAttributes)
|
|
{
|
|
self.titleLabel.text = title;
|
|
return;
|
|
}
|
|
NSMutableAttributedString * attributedTitle =
|
|
[[NSMutableAttributedString alloc] initWithString:title];
|
|
NSDictionary * titleAttributes = isPartialMatching ? unselectedTitleAttributes : selectedTitleAttributes;
|
|
|
|
NSArray<NSValue *> *highlightRanges = result.highlightRanges;
|
|
[attributedTitle addAttributes:titleAttributes range:NSMakeRange(0, title.length)];
|
|
|
|
for (NSValue *rangeValue in highlightRanges) {
|
|
NSRange range = [rangeValue rangeValue];
|
|
if (NSMaxRange(range) <= result.titleText.length) {
|
|
[attributedTitle addAttributes:selectedTitleAttributes range:range];
|
|
} else {
|
|
NSLog(@"Incorrect range: %@ for string: %@", NSStringFromRange(range), result.titleText);
|
|
}
|
|
}
|
|
self.titleLabel.attributedText = attributedTitle;
|
|
[self.titleLabel sizeToFit];
|
|
}
|
|
|
|
- (NSDictionary *)selectedTitleAttributes
|
|
{
|
|
return nil;
|
|
}
|
|
|
|
- (NSDictionary *)unselectedTitleAttributes
|
|
{
|
|
return nil;
|
|
}
|
|
|
|
@end
|