Skip to content

Commit 40d1ee2

Browse files
fix(android): removing inline styles (#672)
# Summary Fixes: #671 This PR fixes removing inline styles within a range while preserving the styles before and after the selected range. ## Test Plan Run reproduction steps from issue: #671 The issue should be resolved. ## Screenshots / Videos Before: https://github.com/user-attachments/assets/b260a081-fd1b-4f96-b615-d595a203a7ba After: https://github.com/user-attachments/assets/a5942796-1cdf-43ca-90c4-450b4fb68c3a ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ❌ | | Android | ✅ | | Web | ❌ | ## Checklist - [x] E2E tests are passing - [x] Required E2E tests have been added (if applicable)
1 parent 99729b4 commit 40d1ee2

4 files changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
appId: swmansion.enriched.example
2+
---
3+
# PR #672 - fix: removing inline styles
4+
- launchApp
5+
6+
- tapOn:
7+
id: 'toggle-screen-button'
8+
9+
- tapOn:
10+
id: 'editor-input'
11+
12+
- tapOn:
13+
id: 'toolbar-bold'
14+
- tapOn:
15+
id: 'toolbar-italic'
16+
- tapOn:
17+
id: 'toolbar-underline'
18+
- tapOn:
19+
id: 'toolbar-strikethrough'
20+
21+
- inputText: 'First line'
22+
- pressKey: Enter
23+
- inputText: 'Second line'
24+
25+
- tapOn:
26+
id: 'toolbar-code-block'
27+
28+
- runFlow:
29+
file: '../subflows/capture_or_assert_screenshot.yaml'
30+
env:
31+
SCREENSHOT_NAME: 'inline_styles_removal'
8.96 KB
Loading
10.9 KB
Loading

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,18 @@ class InlineStyles(
223223
if (spans.isEmpty()) return false
224224

225225
for (span in spans) {
226+
val spanStart = spannable.getSpanStart(span)
227+
val spanEnd = spannable.getSpanEnd(span)
228+
226229
spannable.removeSpan(span)
230+
231+
if (spanStart < start) {
232+
setSpan(spannable, config.clazz, spanStart, start - 1)
233+
}
234+
235+
if (spanEnd > end) {
236+
setSpan(spannable, config.clazz, end, spanEnd)
237+
}
227238
}
228239

229240
return true

0 commit comments

Comments
 (0)