slate-react 0.117.2 → 0.117.3

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.
package/dist/index.js CHANGED
@@ -796,7 +796,22 @@ function createAndroidInputManager(_ref) {
796
796
  insertPositionHint = false;
797
797
  }
798
798
  if (canStoreDiff) {
799
+ var currentSelection = editor.selection;
799
800
  storeDiff(_start.path, _diff);
801
+ if (currentSelection) {
802
+ var newPoint = {
803
+ path: _start.path,
804
+ offset: _start.offset + _text.length
805
+ };
806
+ scheduleAction(function () {
807
+ slate.Transforms.select(editor, {
808
+ anchor: newPoint,
809
+ focus: newPoint
810
+ });
811
+ }, {
812
+ at: newPoint
813
+ });
814
+ }
800
815
  return;
801
816
  }
802
817
  }
@@ -4448,10 +4463,23 @@ var withReact = function withReact(editor) {
4448
4463
  e = slateDom.withDOM(e, clipboardFormatKey);
4449
4464
  var _e = e,
4450
4465
  onChange = _e.onChange,
4451
- apply = _e.apply;
4466
+ apply = _e.apply,
4467
+ insertText = _e.insertText;
4452
4468
  e.getChunkSize = function () {
4453
4469
  return null;
4454
4470
  };
4471
+ if (slateDom.IS_ANDROID) {
4472
+ e.insertText = function (text, options) {
4473
+ // COMPAT: Android devices, specifically Samsung devices, experience cursor jumping.
4474
+ // This issue occurs when the ⁠insertText function is called immediately after typing.
4475
+ // The problem arises because typing schedules a selection change.
4476
+ // However, this selection change is only executed after the ⁠insertText function.
4477
+ // As a result, the already obsolete selection is applied, leading to incorrect
4478
+ // final cursor position.
4479
+ slateDom.EDITOR_TO_PENDING_SELECTION["delete"](e);
4480
+ return insertText(text, options);
4481
+ };
4482
+ }
4455
4483
  e.onChange = function (options) {
4456
4484
  // COMPAT: React < 18 doesn't batch `setState` hook calls, which means
4457
4485
  // that the children and selection can get out of sync for one render