-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathStyleUtils.kt
More file actions
55 lines (47 loc) · 1.73 KB
/
Copy pathStyleUtils.kt
File metadata and controls
55 lines (47 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.swmansion.enriched.textinput.utils
import android.text.Spannable
import com.swmansion.enriched.textinput.spans.EnrichedSpans
import com.swmansion.enriched.textinput.styles.HtmlStyle
fun resolveStyleName(name: String): String? =
when (name) {
"h1" -> EnrichedSpans.H1
"h2" -> EnrichedSpans.H2
"h3" -> EnrichedSpans.H3
"h4" -> EnrichedSpans.H4
"h5" -> EnrichedSpans.H5
"h6" -> EnrichedSpans.H6
"blockquote" -> EnrichedSpans.BLOCK_QUOTE
"codeblock" -> EnrichedSpans.CODE_BLOCK
"unordered_list" -> EnrichedSpans.UNORDERED_LIST
"ordered_list" -> EnrichedSpans.ORDERED_LIST
"checkbox_list" -> EnrichedSpans.CHECKBOX_LIST
"bold" -> EnrichedSpans.BOLD
"italic" -> EnrichedSpans.ITALIC
"underline" -> EnrichedSpans.UNDERLINE
"strikethrough" -> EnrichedSpans.STRIKETHROUGH
"inline_code" -> EnrichedSpans.INLINE_CODE
else -> null
}
fun isInlineShortcutStyle(styleName: String): Boolean {
val resolvedStyle = resolveStyleName(styleName) ?: return false
return EnrichedSpans.inlineSpans.containsKey(resolvedStyle)
}
private val ALIGNMENT_SHORTCUT_STYLES = setOf("left", "center", "right", "justify")
fun isAlignmentShortcutStyle(styleName: String): Boolean = styleName in ALIGNMENT_SHORTCUT_STYLES
fun isStyleBlockedOnRange(
styleName: String,
start: Int,
end: Int,
spannable: Spannable,
htmlStyle: HtmlStyle,
): Boolean {
val mergingConfig =
EnrichedSpans.getMergingConfigForStyle(styleName, htmlStyle) ?: return false
for (blockingStyleName in mergingConfig.blockingStyles) {
val spanClass = EnrichedSpans.allSpans[blockingStyleName]?.clazz ?: continue
if (spannable.getSpans(start, end, spanClass).isNotEmpty()) {
return true
}
}
return false
}