Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,31 @@ class ParametrizedStyles(private val view: EnrichedTextInputView) {
return Triple(result, start, end)
}

private fun canLinkBeApplied(): Boolean {
val mergingConfig = EnrichedSpans.getMergingConfigForStyle(EnrichedSpans.LINK, view.htmlStyle)?: return true
val conflictingStyles = mergingConfig.conflictingStyles
val blockingStyles = mergingConfig.blockingStyles

for (style in blockingStyles) {
if (view.spanState?.getStart(style) != null) return false
}

for (style in conflictingStyles) {
if (view.spanState?.getStart(style) != null) return false
}

return true
}

private fun afterTextChangedLinks(result: Triple<String, Int, Int>) {
// Do not detect link if it's applied manually
if (isSettingLinkSpan) return
if (isSettingLinkSpan || !canLinkBeApplied()) return

val spannable = view.text as Spannable
val (word, start, end) = result

// TODO: Consider using more reliable regex, this one matches almost anything
val urlPattern = android.util.Patterns.WEB_URL.matcher(word)

val spans = spannable.getSpans(start, end, EnrichedLinkSpan::class.java)
for (span in spans) {
spannable.removeSpan(span)
Expand Down
Loading