@chaitrabhairappa/react-native-rich-text-editor 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -211,6 +211,9 @@ class RichTextEditorView(context: Context) : androidx.appcompat.widget.AppCompat
|
|
|
211
211
|
if (!handled) {
|
|
212
212
|
handled = autoContinueListOnEnter(s)
|
|
213
213
|
}
|
|
214
|
+
if (!handled) {
|
|
215
|
+
handled = applyInlineStyleShortcut(s)
|
|
216
|
+
}
|
|
214
217
|
if (!handled) {
|
|
215
218
|
isInternalChange = true
|
|
216
219
|
renumberNumberedLists()
|
|
@@ -1736,6 +1739,64 @@ class RichTextEditorView(context: Context) : androidx.appcompat.widget.AppCompat
|
|
|
1736
1739
|
return false
|
|
1737
1740
|
}
|
|
1738
1741
|
|
|
1742
|
+
private fun applyInlineStyleShortcut(s: Editable?): Boolean {
|
|
1743
|
+
if (s == null) return false
|
|
1744
|
+
|
|
1745
|
+
val start = selectionStart
|
|
1746
|
+
val end = selectionEnd
|
|
1747
|
+
if (start != end || start <= 0 || start > s.length) return false
|
|
1748
|
+
|
|
1749
|
+
var lineStart = start - 1
|
|
1750
|
+
while (lineStart > 0 && s[lineStart - 1] != '\n') {
|
|
1751
|
+
lineStart--
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
val textBeforeCursor = s.subSequence(lineStart, start).toString()
|
|
1755
|
+
if (textBeforeCursor.length < 3) return false
|
|
1756
|
+
|
|
1757
|
+
data class ShortcutPattern(
|
|
1758
|
+
val regex: Regex,
|
|
1759
|
+
val apply: (Editable, Int, Int) -> Unit,
|
|
1760
|
+
)
|
|
1761
|
+
|
|
1762
|
+
val patterns = listOf(
|
|
1763
|
+
ShortcutPattern(Regex("(^|\\s)\\*([^*\\n]+)\\*$")) { editable, spanStart, spanEnd ->
|
|
1764
|
+
editable.setSpan(StyleSpan(Typeface.BOLD), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
1765
|
+
},
|
|
1766
|
+
ShortcutPattern(Regex("(^|\\s)_([^_\\n]+)_$")) { editable, spanStart, spanEnd ->
|
|
1767
|
+
editable.setSpan(StyleSpan(Typeface.ITALIC), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
1768
|
+
},
|
|
1769
|
+
ShortcutPattern(Regex("(^|\\s)~([^~\\n]+)~$")) { editable, spanStart, spanEnd ->
|
|
1770
|
+
editable.setSpan(StrikethroughSpan(), spanStart, spanEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
1771
|
+
}
|
|
1772
|
+
)
|
|
1773
|
+
|
|
1774
|
+
for (pattern in patterns) {
|
|
1775
|
+
val match = pattern.regex.find(textBeforeCursor) ?: continue
|
|
1776
|
+
val prefixWhitespaceLen = match.groupValues[1].length
|
|
1777
|
+
val styledText = match.groupValues[2]
|
|
1778
|
+
if (styledText.isEmpty()) continue
|
|
1779
|
+
|
|
1780
|
+
val markerStartInLine = match.range.first + prefixWhitespaceLen
|
|
1781
|
+
val markerStart = lineStart + markerStartInLine
|
|
1782
|
+
if (markerStart < 0 || markerStart > start) continue
|
|
1783
|
+
|
|
1784
|
+
isInternalChange = true
|
|
1785
|
+
s.replace(markerStart, start, styledText)
|
|
1786
|
+
|
|
1787
|
+
val styleStart = markerStart
|
|
1788
|
+
val styleEnd = markerStart + styledText.length
|
|
1789
|
+
if (styleStart < styleEnd && styleEnd <= s.length) {
|
|
1790
|
+
pattern.apply(s, styleStart, styleEnd)
|
|
1791
|
+
setSelection(styleEnd)
|
|
1792
|
+
}
|
|
1793
|
+
isInternalChange = false
|
|
1794
|
+
return true
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
return false
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1739
1800
|
private fun renumberNumberedLists() {
|
|
1740
1801
|
val editable = text ?: return
|
|
1741
1802
|
val fullText = editable.toString()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chaitrabhairappa/react-native-rich-text-editor",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "A high-performance native rich text editor for React Native (New Architecture / Fabric only)",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|