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 @@ -15,6 +15,8 @@ import java.io.File

class ParametrizedStyles(private val editorView: ReactNativeRichTextEditorView) {
private var mentionStart: Int? = null
private var isSettingLinkSpan = false

var mentionIndicators: Array<String> = emptyArray<String>()

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

fun setLinkSpan(start: Int, end: Int, text: String, url: String) {
isSettingLinkSpan = true

val spannable = editorView.text as SpannableStringBuilder
val spans = spannable.getSpans(start, end, EditorLinkSpan::class.java)
for (span in spans) {
Expand All @@ -50,6 +54,7 @@ class ParametrizedStyles(private val editorView: ReactNativeRichTextEditorView)
spannable.setSpan(span, safeStart, safeEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)

editorView.selection?.validateStyles()
isSettingLinkSpan = false
}

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

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

Expand Down
Loading