@textbus/platform-browser 4.0.0-alpha.55 → 4.0.0-alpha.56

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.
@@ -418,7 +418,33 @@ let SelectionBridge = class SelectionBridge {
418
418
  this.listen(this.connector);
419
419
  return;
420
420
  }
421
- this.nativeSelection.setBaseAndExtent(anchor.node, anchor.offset, focus.node, focus.offset);
421
+ function tryOffset(position) {
422
+ if (!position.node) {
423
+ return;
424
+ }
425
+ if (position.node.nodeType === Node.TEXT_NODE) {
426
+ const len = position.node.textContent.length;
427
+ if (position.offset > len) {
428
+ position.offset = len;
429
+ }
430
+ }
431
+ else if (position.node.nodeType === Node.ELEMENT_NODE) {
432
+ const len = position.node.childNodes.length;
433
+ if (position.offset > len) {
434
+ position.offset = len;
435
+ }
436
+ }
437
+ }
438
+ try {
439
+ tryOffset(focus);
440
+ tryOffset(anchor);
441
+ this.nativeSelection.setBaseAndExtent(anchor.node, anchor.offset, focus.node, focus.offset);
442
+ }
443
+ catch (e) {
444
+ setTimeout(() => {
445
+ throw e;
446
+ });
447
+ }
422
448
  if (this.nativeSelection.rangeCount) {
423
449
  const nativeRange = this.nativeSelection.getRangeAt(0);
424
450
  this.selectionChangeEvent.next(nativeRange);
@@ -1259,6 +1285,7 @@ let MagicInput = class MagicInput extends Input {
1259
1285
  }), fromEvent(textarea, 'compositionend').subscribe(() => {
1260
1286
  isWriting = false;
1261
1287
  }), fromEvent(textarea, 'beforeinput').subscribe(ev => {
1288
+ this.ignoreComposition = false;
1262
1289
  if (this.isSafari) {
1263
1290
  if (ev.inputType === 'insertFromComposition') {
1264
1291
  isIgnore = true;
package/bundles/index.js CHANGED
@@ -420,7 +420,33 @@ exports.SelectionBridge = class SelectionBridge {
420
420
  this.listen(this.connector);
421
421
  return;
422
422
  }
423
- this.nativeSelection.setBaseAndExtent(anchor.node, anchor.offset, focus.node, focus.offset);
423
+ function tryOffset(position) {
424
+ if (!position.node) {
425
+ return;
426
+ }
427
+ if (position.node.nodeType === Node.TEXT_NODE) {
428
+ const len = position.node.textContent.length;
429
+ if (position.offset > len) {
430
+ position.offset = len;
431
+ }
432
+ }
433
+ else if (position.node.nodeType === Node.ELEMENT_NODE) {
434
+ const len = position.node.childNodes.length;
435
+ if (position.offset > len) {
436
+ position.offset = len;
437
+ }
438
+ }
439
+ }
440
+ try {
441
+ tryOffset(focus);
442
+ tryOffset(anchor);
443
+ this.nativeSelection.setBaseAndExtent(anchor.node, anchor.offset, focus.node, focus.offset);
444
+ }
445
+ catch (e) {
446
+ setTimeout(() => {
447
+ throw e;
448
+ });
449
+ }
424
450
  if (this.nativeSelection.rangeCount) {
425
451
  const nativeRange = this.nativeSelection.getRangeAt(0);
426
452
  this.selectionChangeEvent.next(nativeRange);
@@ -1261,6 +1287,7 @@ exports.MagicInput = class MagicInput extends Input {
1261
1287
  }), stream.fromEvent(textarea, 'compositionend').subscribe(() => {
1262
1288
  isWriting = false;
1263
1289
  }), stream.fromEvent(textarea, 'beforeinput').subscribe(ev => {
1290
+ this.ignoreComposition = false;
1264
1291
  if (this.isSafari) {
1265
1292
  if (ev.inputType === 'insertFromComposition') {
1266
1293
  isIgnore = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/platform-browser",
3
- "version": "4.0.0-alpha.55",
3
+ "version": "4.0.0-alpha.56",
4
4
  "description": "Textbus is a rich text editor and framework that is highly customizable and extensible to achieve rich wysiwyg effects.",
5
5
  "main": "./bundles/index.js",
6
6
  "module": "./bundles/index.esm.js",
@@ -26,8 +26,8 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@tanbo/stream": "^1.2.4",
29
- "@textbus/collaborate": "^4.0.0-alpha.55",
30
- "@textbus/core": "^4.0.0-alpha.55",
29
+ "@textbus/collaborate": "^4.0.0-alpha.56",
30
+ "@textbus/core": "^4.0.0-alpha.56",
31
31
  "@viewfly/core": "^1.0.0-alpha.6"
32
32
  },
33
33
  "devDependencies": {
@@ -48,5 +48,5 @@
48
48
  "bugs": {
49
49
  "url": "https://github.com/textbus/textbus.git/issues"
50
50
  },
51
- "gitHead": "22e85887dd98c3689799dfd217bfc1f845cb28a8"
51
+ "gitHead": "1926a5b6ac25ece853fefe454488a5935b19bf62"
52
52
  }