Skip to content

Commit 8e2f9e5

Browse files
authored
fix: android - links detection (#122)
* fix: links detection * chore: make it private
1 parent 09f8693 commit 8e2f9e5

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

android/src/main/java/com/swmansion/reactnativerichtexteditor/styles/ParametrizedStyles.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import java.io.File
1515

1616
class ParametrizedStyles(private val editorView: ReactNativeRichTextEditorView) {
1717
private var mentionStart: Int? = null
18+
private var isSettingLinkSpan = false
19+
1820
var mentionIndicators: Array<String> = emptyArray<String>()
1921

2022
fun <T>removeSpansForRange(spannable: Spannable, start: Int, end: Int, clazz: Class<T>): Boolean {
@@ -32,6 +34,8 @@ class ParametrizedStyles(private val editorView: ReactNativeRichTextEditorView)
3234
}
3335

3436
fun setLinkSpan(start: Int, end: Int, text: String, url: String) {
37+
isSettingLinkSpan = true
38+
3539
val spannable = editorView.text as SpannableStringBuilder
3640
val spans = spannable.getSpans(start, end, EditorLinkSpan::class.java)
3741
for (span in spans) {
@@ -50,6 +54,7 @@ class ParametrizedStyles(private val editorView: ReactNativeRichTextEditorView)
5054
spannable.setSpan(span, safeStart, safeEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
5155

5256
editorView.selection?.validateStyles()
57+
isSettingLinkSpan = false
5358
}
5459

5560
fun afterTextChanged(s: Editable, endCursorPosition: Int) {
@@ -100,6 +105,8 @@ class ParametrizedStyles(private val editorView: ReactNativeRichTextEditorView)
100105
}
101106

102107
private fun afterTextChangedLinks(result: Triple<String, Int, Int>) {
108+
// Do not detect link if it's applied manually
109+
if (isSettingLinkSpan) return
103110
val spannable = editorView.text as Spannable
104111
val (word, start, end) = result
105112

0 commit comments

Comments
 (0)