react-native-typerich 0.1.6 → 0.1.7

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.
@@ -364,12 +364,25 @@ class TypeRichTextInputView : AppCompatEditText {
364
364
  fun setValue(value: CharSequence?) {
365
365
  if (value == null) return
366
366
 
367
+ val editText = this
368
+
369
+ // Save current selection BEFORE text change
370
+ val prevStart = editText.selectionStart
371
+ val prevEnd = editText.selectionEnd
372
+
367
373
  runAsATransaction {
368
- setText(value.toString())
369
- setSelection(text?.length ?: 0)
374
+ if (editText.text.toString() != value.toString()) {
375
+ setText(value.toString())
376
+ }
377
+
378
+ val len = editText.text?.length ?: 0
379
+ val start = prevStart.coerceIn(0, len)
380
+ val end = prevEnd.coerceIn(0, len)
381
+
382
+ setSelection(start, end)
370
383
  }
371
384
  }
372
-
385
+
373
386
  fun setAutoFocus(autoFocus: Boolean) {
374
387
  this.autoFocus = autoFocus
375
388
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-typerich",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Textinput replacement",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",