@iamakulov/codemirror-view 6.39.10 → 6.39.11

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.cjs CHANGED
@@ -4377,7 +4377,8 @@ class InputState {
4377
4377
  firefoxCopyCutHack(view.contentDOM.ownerDocument);
4378
4378
  }
4379
4379
  handleEvent(event) {
4380
- if (!eventBelongsToEditor(this.view, event) || this.ignoreDuringComposition(event))
4380
+ if (!eventBelongsToEditor(this.view, event) || this.ignoreDuringComposition(event) ||
4381
+ this.ignoreDuringTransientFocus(event))
4381
4382
  return;
4382
4383
  if (event.type == "keydown" && this.keydown(event))
4383
4384
  return;
@@ -4481,6 +4482,22 @@ class InputState {
4481
4482
  }
4482
4483
  return false;
4483
4484
  }
4485
+ ignoreDuringTransientFocus(event) {
4486
+ // Detect transient focus from parent editor selection operations. When a
4487
+ // parent contentEditable (like ProseMirror) performs a selection using
4488
+ // Selection.collapse() + Selection.extend() [1], and Selection.collapse()
4489
+ // collapses to a position where CodeMirror is, the browser will fire a focus
4490
+ // event on this CodeMirror. This focus is transient and should be ignored;
4491
+ // otherwise, our focus logic will undo the parent’s selection.
4492
+ // [1] https://github.com/ProseMirror/prosemirror-view/blob/76c7c47f03730b18397b94bd269ece8a9cb7f486/src/viewdesc.ts#L464-L468
4493
+ if (event.type === "focus") {
4494
+ let sel = getSelection(this.view.root);
4495
+ if (sel && sel.anchorNode && !this.view.contentDOM.contains(sel.anchorNode)) {
4496
+ return true;
4497
+ }
4498
+ }
4499
+ return false;
4500
+ }
4484
4501
  startMouseSelection(mouseSelection) {
4485
4502
  if (this.mouseSelection)
4486
4503
  this.mouseSelection.destroy();
@@ -4690,19 +4707,6 @@ function eventBelongsToEditor(view, event) {
4690
4707
  if (!node || node.nodeType == 11 ||
4691
4708
  ((tile = Tile.get(node)) && tile.isWidget() && !tile.isHidden && tile.widget.ignoreEvent(event)))
4692
4709
  return false;
4693
- // Detect transient focus from parent editor selection operations. When a
4694
- // parent contentEditable (like ProseMirror) performs a selection using
4695
- // Selection.collapse() + Selection.extend() [1], and Selection.collapse()
4696
- // collapses to a position where CodeMirror is, the browser will fire a focus
4697
- // event on this editor. This focus is transient and should be ignored;
4698
- // otherwise, our focus logic will undo the parent’s selection.
4699
- // [1] https://github.com/ProseMirror/prosemirror-view/blob/76c7c47f03730b18397b94bd269ece8a9cb7f486/src/viewdesc.ts#L464-L468
4700
- if (event.type == "focus") {
4701
- let sel = getSelection(view.root);
4702
- if (sel && sel.anchorNode && !view.contentDOM.contains(sel.anchorNode)) {
4703
- return false;
4704
- }
4705
- }
4706
4710
  return true;
4707
4711
  }
4708
4712
  const handlers = Object.create(null);
package/dist/index.js CHANGED
@@ -4373,7 +4373,8 @@ class InputState {
4373
4373
  firefoxCopyCutHack(view.contentDOM.ownerDocument);
4374
4374
  }
4375
4375
  handleEvent(event) {
4376
- if (!eventBelongsToEditor(this.view, event) || this.ignoreDuringComposition(event))
4376
+ if (!eventBelongsToEditor(this.view, event) || this.ignoreDuringComposition(event) ||
4377
+ this.ignoreDuringTransientFocus(event))
4377
4378
  return;
4378
4379
  if (event.type == "keydown" && this.keydown(event))
4379
4380
  return;
@@ -4477,6 +4478,22 @@ class InputState {
4477
4478
  }
4478
4479
  return false;
4479
4480
  }
4481
+ ignoreDuringTransientFocus(event) {
4482
+ // Detect transient focus from parent editor selection operations. When a
4483
+ // parent contentEditable (like ProseMirror) performs a selection using
4484
+ // Selection.collapse() + Selection.extend() [1], and Selection.collapse()
4485
+ // collapses to a position where CodeMirror is, the browser will fire a focus
4486
+ // event on this CodeMirror. This focus is transient and should be ignored;
4487
+ // otherwise, our focus logic will undo the parent’s selection.
4488
+ // [1] https://github.com/ProseMirror/prosemirror-view/blob/76c7c47f03730b18397b94bd269ece8a9cb7f486/src/viewdesc.ts#L464-L468
4489
+ if (event.type === "focus") {
4490
+ let sel = getSelection(this.view.root);
4491
+ if (sel && sel.anchorNode && !this.view.contentDOM.contains(sel.anchorNode)) {
4492
+ return true;
4493
+ }
4494
+ }
4495
+ return false;
4496
+ }
4480
4497
  startMouseSelection(mouseSelection) {
4481
4498
  if (this.mouseSelection)
4482
4499
  this.mouseSelection.destroy();
@@ -4686,19 +4703,6 @@ function eventBelongsToEditor(view, event) {
4686
4703
  if (!node || node.nodeType == 11 ||
4687
4704
  ((tile = Tile.get(node)) && tile.isWidget() && !tile.isHidden && tile.widget.ignoreEvent(event)))
4688
4705
  return false;
4689
- // Detect transient focus from parent editor selection operations. When a
4690
- // parent contentEditable (like ProseMirror) performs a selection using
4691
- // Selection.collapse() + Selection.extend() [1], and Selection.collapse()
4692
- // collapses to a position where CodeMirror is, the browser will fire a focus
4693
- // event on this editor. This focus is transient and should be ignored;
4694
- // otherwise, our focus logic will undo the parent’s selection.
4695
- // [1] https://github.com/ProseMirror/prosemirror-view/blob/76c7c47f03730b18397b94bd269ece8a9cb7f486/src/viewdesc.ts#L464-L468
4696
- if (event.type == "focus") {
4697
- let sel = getSelection(view.root);
4698
- if (sel && sel.anchorNode && !view.contentDOM.contains(sel.anchorNode)) {
4699
- return false;
4700
- }
4701
- }
4702
4706
  return true;
4703
4707
  }
4704
4708
  const handlers = /*@__PURE__*/Object.create(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iamakulov/codemirror-view",
3
- "version": "6.39.10",
3
+ "version": "6.39.11",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",