@textbus/platform-browser 3.7.3 → 3.7.5

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.
@@ -264,7 +264,30 @@ let SelectionBridge = class SelectionBridge {
264
264
  this.listen(this.connector);
265
265
  return;
266
266
  }
267
- this.nativeSelection.setBaseAndExtent(anchor.node, anchor.offset, focus.node, focus.offset);
267
+ function tryOffset(position) {
268
+ if (position.node.nodeType === Node.TEXT_NODE) {
269
+ const len = position.node.textContent.length;
270
+ if (position.offset > len) {
271
+ position.offset = len;
272
+ }
273
+ }
274
+ else if (position.node.nodeType === Node.ELEMENT_NODE) {
275
+ const len = position.node.childNodes.length;
276
+ if (position.offset > len) {
277
+ position.offset = len;
278
+ }
279
+ }
280
+ }
281
+ tryOffset(focus);
282
+ tryOffset(anchor);
283
+ try {
284
+ this.nativeSelection.setBaseAndExtent(anchor.node, anchor.offset, focus.node, focus.offset);
285
+ }
286
+ catch (e) {
287
+ setTimeout(() => {
288
+ throw e;
289
+ });
290
+ }
268
291
  if (this.nativeSelection.rangeCount) {
269
292
  const nativeRange = this.nativeSelection.getRangeAt(0);
270
293
  this.selectionChangeEvent.next(nativeRange);
@@ -1692,7 +1715,7 @@ let MagicInput = class MagicInput extends Input {
1692
1715
  this.handleDefaultActions(textarea);
1693
1716
  }
1694
1717
  handleDefaultActions(textarea) {
1695
- this.subscription.add(fromEvent(document, 'copy').subscribe(ev => {
1718
+ this.subscription.add(fromEvent(isFirefox() ? textarea : document, 'copy').subscribe(ev => {
1696
1719
  const selection = this.selection;
1697
1720
  if (!selection.isSelected) {
1698
1721
  return;
@@ -2068,7 +2091,7 @@ let NativeInput = class NativeInput extends Input {
2068
2091
  this.subscription.unsubscribe();
2069
2092
  }
2070
2093
  handleDefaultActions(textarea) {
2071
- this.subscription.add(fromEvent(document, 'copy').subscribe(ev => {
2094
+ this.subscription.add(fromEvent(isFirefox() ? textarea : document, 'copy').subscribe(ev => {
2072
2095
  const selection = this.selection;
2073
2096
  if (!selection.isSelected) {
2074
2097
  return;
package/bundles/index.js CHANGED
@@ -266,7 +266,30 @@ exports.SelectionBridge = class SelectionBridge {
266
266
  this.listen(this.connector);
267
267
  return;
268
268
  }
269
- this.nativeSelection.setBaseAndExtent(anchor.node, anchor.offset, focus.node, focus.offset);
269
+ function tryOffset(position) {
270
+ if (position.node.nodeType === Node.TEXT_NODE) {
271
+ const len = position.node.textContent.length;
272
+ if (position.offset > len) {
273
+ position.offset = len;
274
+ }
275
+ }
276
+ else if (position.node.nodeType === Node.ELEMENT_NODE) {
277
+ const len = position.node.childNodes.length;
278
+ if (position.offset > len) {
279
+ position.offset = len;
280
+ }
281
+ }
282
+ }
283
+ tryOffset(focus);
284
+ tryOffset(anchor);
285
+ try {
286
+ this.nativeSelection.setBaseAndExtent(anchor.node, anchor.offset, focus.node, focus.offset);
287
+ }
288
+ catch (e) {
289
+ setTimeout(() => {
290
+ throw e;
291
+ });
292
+ }
270
293
  if (this.nativeSelection.rangeCount) {
271
294
  const nativeRange = this.nativeSelection.getRangeAt(0);
272
295
  this.selectionChangeEvent.next(nativeRange);
@@ -1694,7 +1717,7 @@ exports.MagicInput = class MagicInput extends Input {
1694
1717
  this.handleDefaultActions(textarea);
1695
1718
  }
1696
1719
  handleDefaultActions(textarea) {
1697
- this.subscription.add(stream.fromEvent(document, 'copy').subscribe(ev => {
1720
+ this.subscription.add(stream.fromEvent(isFirefox() ? textarea : document, 'copy').subscribe(ev => {
1698
1721
  const selection = this.selection;
1699
1722
  if (!selection.isSelected) {
1700
1723
  return;
@@ -2070,7 +2093,7 @@ exports.NativeInput = class NativeInput extends Input {
2070
2093
  this.subscription.unsubscribe();
2071
2094
  }
2072
2095
  handleDefaultActions(textarea) {
2073
- this.subscription.add(stream.fromEvent(document, 'copy').subscribe(ev => {
2096
+ this.subscription.add(stream.fromEvent(isFirefox() ? textarea : document, 'copy').subscribe(ev => {
2074
2097
  const selection = this.selection;
2075
2098
  if (!selection.isSelected) {
2076
2099
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/platform-browser",
3
- "version": "3.7.3",
3
+ "version": "3.7.5",
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",
@@ -48,5 +48,5 @@
48
48
  "bugs": {
49
49
  "url": "https://github.com/textbus/textbus.git/issues"
50
50
  },
51
- "gitHead": "db4e1056d62087b217bbe5f2c1535e5f4a4d1467"
51
+ "gitHead": "799ab8aafd2d8ed262a797da7872df10720c694d"
52
52
  }