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

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);
@@ -523,10 +549,10 @@ let SelectionBridge = class SelectionBridge {
523
549
  }
524
550
  minLeft = rect2.left;
525
551
  minTop = rect2.top;
526
- oldPosition = position;
552
+ // oldPosition = position
527
553
  }
528
554
  if (isToPrevLine) {
529
- if (rect2.left < startLeft) {
555
+ if (rect2.left <= startLeft) {
530
556
  return position;
531
557
  }
532
558
  if (oldPosition) {
@@ -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);
@@ -525,10 +551,10 @@ exports.SelectionBridge = class SelectionBridge {
525
551
  }
526
552
  minLeft = rect2.left;
527
553
  minTop = rect2.top;
528
- oldPosition = position;
554
+ // oldPosition = position
529
555
  }
530
556
  if (isToPrevLine) {
531
- if (rect2.left < startLeft) {
557
+ if (rect2.left <= startLeft) {
532
558
  return position;
533
559
  }
534
560
  if (oldPosition) {
@@ -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.57",
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,9 +26,9 @@
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",
31
- "@viewfly/core": "^1.0.0-alpha.6"
29
+ "@textbus/collaborate": "^4.0.0-alpha.57",
30
+ "@textbus/core": "^4.0.0-alpha.57",
31
+ "@viewfly/core": "^1.0.0-alpha.9"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@rollup/plugin-commonjs": "^23.0.2",
@@ -48,5 +48,5 @@
48
48
  "bugs": {
49
49
  "url": "https://github.com/textbus/textbus.git/issues"
50
50
  },
51
- "gitHead": "22e85887dd98c3689799dfd217bfc1f845cb28a8"
51
+ "gitHead": "0a8d42b5be9e2fd24dcbdf31de32e820fadfbe41"
52
52
  }