Skip to content
Merged
Show file tree
Hide file tree
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 @@ -51,6 +51,7 @@ class ReactNativeRichTextEditorView : AppCompatEditText {
val listStyles: ListStyles? = ListStyles(this)
val parametrizedStyles: ParametrizedStyles? = ParametrizedStyles(this)
var isSettingValue: Boolean = false
var isRemovingMany: Boolean = false

val mentionHandler: MentionHandler? = MentionHandler(this)
var richTextStyle: RichTextStyle = RichTextStyle(this, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class EditorSelection(private val editorView: ReactNativeRichTextEditorView) {

if (isZeroWidthSelection() && !editorView.isSettingValue) {
editorView.setSelection(start + 1)
return
shouldValidateStyles = false
}

if (!shouldValidateStyles) return
Expand All @@ -62,8 +62,15 @@ class EditorSelection(private val editorView: ReactNativeRichTextEditorView) {
fun validateStyles() {
val state = editorView.spanState ?: return

for ((style, config) in EditorSpans.inlineSpans) {
state.setStart(style, getInlineStyleStart(config.clazz))
// We don't validate inline styles when removing many characters at once
// We don't want to remove styles on auto-correction
// If user removes many characters at once, we want to keep the styles config
if (!editorView.isRemovingMany) {
for ((style, config) in EditorSpans.inlineSpans) {
state.setStart(style, getInlineStyleStart(config.clazz))
}
} else {
editorView.isRemovingMany = false
}

for ((style, config) in EditorSpans.paragraphSpans) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class EditorTextWatcher(private val editorView: ReactNativeRichTextEditorView) :
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
endCursorPosition = start + count
editorView.layoutManager.measureSize(s ?: "")
editorView.isRemovingMany = !editorView.isSettingValue && before > count + 1
}

override fun afterTextChanged(s: Editable?) {
Expand Down
Loading