Skip to content

Commit e9999fc

Browse files
fix(android): remove link styling inside codeblock (#557)
# Summary Fixes: #554 This PR adds link and mention as conflicting styles to codeblock ## Test Plan Run reproduction steps from: #554 The issue should be resolved. ## Screenshots / Videos https://github.com/user-attachments/assets/c485ffdb-a669-486c-ba20-19339d8a5e7b ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ❌ | | Android | ✅ | ## Checklist - [ ] E2E tests are passing - [ ] Required E2E tests have been added (if applicable) --------- Co-authored-by: Igor Furgała <74370735+exploIF@users.noreply.github.com>
1 parent 16ee2a8 commit e9999fc

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputView.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,13 @@ class EnrichedTextInputView :
897897
val isValid = verifyStyle(name)
898898
if (!isValid) return
899899

900-
toggleStyle(name)
900+
val (rangeStart, rangeEnd) = getTargetRange(name)
901+
902+
runAsATransaction {
903+
toggleStyle(name)
904+
}
905+
906+
parametrizedStyles?.onStyleToggled(name, rangeStart, rangeEnd)
901907
}
902908

903909
fun toggleCheckboxListItem(checked: Boolean) {

android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedSpans.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ object EnrichedSpans {
194194
CHECKBOX_LIST,
195195
BLOCK_QUOTE,
196196
INLINE_CODE,
197+
LINK,
198+
MENTION,
197199
),
198200
)
199201
}

android/src/main/java/com/swmansion/enriched/textinput/styles/ParametrizedStyles.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ class ParametrizedStyles(
9494
afterTextChangedMentions(s, startCursorPosition)
9595
}
9696

97+
fun onStyleToggled(
98+
name: String,
99+
start: Int,
100+
end: Int,
101+
) {
102+
// Run afterTextChangedLinks on the range affected by the style toggle to re-detect links.
103+
// For example, toggling a code block on and off will restore automatically detected links.
104+
val linkConfig = EnrichedSpans.getMergingConfigForStyle(EnrichedSpans.LINK, view.htmlStyle) ?: return
105+
if (name in linkConfig.blockingStyles || name in linkConfig.conflictingStyles) {
106+
afterTextChangedLinks(start, end)
107+
}
108+
}
109+
97110
fun detectLinksInRange(
98111
spannable: Spannable,
99112
start: Int,
@@ -220,8 +233,8 @@ class ParametrizedStyles(
220233
) {
221234
// Do not detect link if it's applied manually
222235
if (isSettingLinkSpan || !canLinkBeApplied()) return
223-
224236
val spannable = view.text as? Spannable ?: return
237+
225238
val affectedRange = getLinksAffectedRange(spannable, editStart, editEnd)
226239
detectLinksInRange(spannable, affectedRange.first, affectedRange.last)
227240
}

0 commit comments

Comments
 (0)