Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
BF: matrix.to links containing room ids are not hyperlinked
Browse files Browse the repository at this point in the history
  • Loading branch information
manuroe committed Jan 18, 2017
1 parent 3c6d990 commit c8a87db
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions MatrixKit/Utils/MXKEventFormatter.m
Expand Up @@ -1195,6 +1195,8 @@ - (NSAttributedString*)postRenderAttributedString:(NSAttributedString*)attribute

- (void)createLinksInAttributedString:(NSAttributedString*)attributedString matchingRegex:(NSRegularExpression*)regex withWorkingAttributedString:(NSMutableAttributedString**)mutableAttributedString
{
__block NSArray *linkMatches;

// Enumerate each string matching the regex
[regex enumerateMatchesInString:attributedString.string options:0 range:NSMakeRange(0, attributedString.length) usingBlock:^(NSTextCheckingResult *match, NSMatchingFlags flags, BOOL *stop) {

Expand All @@ -1209,6 +1211,29 @@ - (void)createLinksInAttributedString:(NSAttributedString*)attributedString matc
}
}];

// Do not create a link if the match is part of an http link.
// The http link will be automatically generated by the UI afterwards.
// So, do not break it now by adding a link on a subset of this http link.
if (!hasAlreadyLink)
{
if (!linkMatches)
{
// Search for the links in the string only once
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
linkMatches = [detector matchesInString:attributedString.string options:0 range:NSMakeRange(0, attributedString.length)];
}

for (NSTextCheckingResult *linkMatch in linkMatches)
{
// If the match is fully in the link, skip it
if (NSIntersectionRange(match.range, linkMatch.range).length == match.range.length)
{
hasAlreadyLink = YES;
break;
}
}
}

if (!hasAlreadyLink)
{
// Create the output string only if it is necessary because attributed strings cost CPU
Expand Down

0 comments on commit c8a87db

Please sign in to comment.