Skip to content

Commit

Permalink
Rename for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Dec 13, 2021
1 parent ab70ee5 commit 04d23ce
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions vector/src/main/java/im/vector/app/core/linkify/VectorLinkify.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object VectorLinkify {

if (keepExistingUrlSpan) {
// Keep track of existing URLSpans, and mark them as important
spannable.forEachSpanIndexed { _, urlSpan, start, end ->
spannable.forEachUrlSpanIndexed { _, urlSpan, start, end ->
createdSpans.add(LinkSpec(URLSpan(urlSpan.url), start, end, important = true))
}
}
Expand All @@ -39,15 +39,15 @@ object VectorLinkify {
LinkifyCompat.addLinks(spannable, Linkify.WEB_URLS or Linkify.EMAIL_ADDRESSES or Linkify.PHONE_NUMBERS)

// we might want to modify some matches
spannable.forEachSpanIndexed { _, urlSpan, start, end ->
spannable.forEachUrlSpanIndexed { _, urlSpan, start, end ->
spannable.removeSpan(urlSpan)

// remove short PN, too much false positive
if (urlSpan.url?.startsWith("tel:") == true) {
if (end - start > 6) { // Do not match under 7 digit
createdSpans.add(LinkSpec(URLSpan(urlSpan.url), start, end))
}
return@forEachSpanIndexed
return@forEachUrlSpanIndexed
}

// include mailto: if found before match
Expand All @@ -60,7 +60,7 @@ object VectorLinkify {
createdSpans.add(LinkSpec(URLSpan(urlSpan.url), start, end))
}

return@forEachSpanIndexed
return@forEachUrlSpanIndexed
}

// Handle url matches
Expand All @@ -70,7 +70,7 @@ object VectorLinkify {
// modify the span to include the slash
val spec = LinkSpec(URLSpan(urlSpan.url + "/"), start, end + 1)
createdSpans.add(spec)
return@forEachSpanIndexed
return@forEachUrlSpanIndexed
}
// Try to do something for ending ) issues/3020
if (spannable[end - 1] == ')') {
Expand All @@ -87,15 +87,15 @@ object VectorLinkify {
val span = URLSpan(spannable.substring(start, end - 1))
val spec = LinkSpec(span, start, end - 1)
createdSpans.add(spec)
return@forEachSpanIndexed
return@forEachUrlSpanIndexed
}
}

createdSpans.add(LinkSpec(URLSpan(urlSpan.url), start, end))
}

LinkifyCompat.addLinks(spannable, VectorAutoLinkPatterns.GEO_URI.toPattern(), "geo:", arrayOf("geo:"), geoMatchFilter, null)
spannable.forEachSpanIndexed { _, urlSpan, start, end ->
spannable.forEachUrlSpanIndexed { _, urlSpan, start, end ->
spannable.removeSpan(urlSpan)
createdSpans.add(LinkSpec(URLSpan(urlSpan.url), start, end))
}
Expand Down Expand Up @@ -174,7 +174,7 @@ object VectorLinkify {
return@MatchFilter true
}

private inline fun Spannable.forEachSpanIndexed(action: (index: Int, urlSpan: URLSpan, start: Int, end: Int) -> Unit) {
private inline fun Spannable.forEachUrlSpanIndexed(action: (index: Int, urlSpan: URLSpan, start: Int, end: Int) -> Unit) {
getSpans(0, length, URLSpan::class.java)
.forEachIndexed { index, urlSpan ->
val start = getSpanStart(urlSpan)
Expand Down

0 comments on commit 04d23ce

Please sign in to comment.