@codemirror/view 6.15.0 → 6.15.2

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/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 6.15.2 (2023-07-18)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix the check that made sure compositions are dropped when the selection is moved.
6
+
7
+ ## 6.15.1 (2023-07-18)
8
+
9
+ ### Bug fixes
10
+
11
+ Fix a regression that could cause the composition content to be drawn incorrectly.
12
+
1
13
  ## 6.15.0 (2023-07-17)
2
14
 
3
15
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -2502,7 +2502,7 @@ class DocView extends ContentView {
2502
2502
  this.view = view;
2503
2503
  this.decorations = [];
2504
2504
  this.dynamicDecorationMap = [];
2505
- this.hasComposition = false;
2505
+ this.hasComposition = null;
2506
2506
  this.markedForComposition = new Set;
2507
2507
  // Track a minimum width for the editor. When measuring sizes in
2508
2508
  // measureVisibleLineHeights, this is updated to point at the width
@@ -2542,9 +2542,13 @@ class DocView extends ContentView {
2542
2542
  }
2543
2543
  }
2544
2544
  let composition = this.view.inputState.composing < 0 ? null : findCompositionRange(this.view, update.changes);
2545
- if (this.hasComposition)
2545
+ if (this.hasComposition) {
2546
2546
  this.markedForComposition.clear();
2547
- this.hasComposition = !!composition;
2547
+ let { from, to } = this.hasComposition;
2548
+ changedRanges = new ChangedRange(from, to, update.changes.mapPos(from, -1), update.changes.mapPos(to, 1))
2549
+ .addToSet(changedRanges.slice());
2550
+ }
2551
+ this.hasComposition = composition ? { from: composition.range.fromB, to: composition.range.toB } : null;
2548
2552
  // When the DOM nodes around the selection are moved to another
2549
2553
  // parent, Chrome sometimes reports a different selection through
2550
2554
  // getSelection than the one that it actually shows to the user.
@@ -2613,9 +2617,16 @@ class DocView extends ContentView {
2613
2617
  openStart = before.openStart;
2614
2618
  openEnd = after.openEnd;
2615
2619
  let compLine = this.compositionView(composition);
2616
- compLine.merge(compLine.length, compLine.length, after.content[0], false, after.openStart, 0);
2617
- compLine.merge(0, 0, before.content[before.content.length - 1], true, 0, before.openEnd);
2618
- content = before.content.slice(0, before.content.length - 1).concat(compLine).concat(after.content.slice(1));
2620
+ if (after.content.length) {
2621
+ compLine.breakAfter = after.content[0].breakAfter;
2622
+ if (compLine.merge(compLine.length, compLine.length, after.content[0], false, after.openStart, 0))
2623
+ after.content.shift();
2624
+ }
2625
+ if (before.content.length) {
2626
+ if (compLine.merge(0, 0, before.content[before.content.length - 1], true, 0, before.openEnd))
2627
+ before.content.pop();
2628
+ }
2629
+ content = before.content.concat(compLine).concat(after.content);
2619
2630
  }
2620
2631
  else {
2621
2632
  ({ content, breakAtStart, openStart, openEnd } =
@@ -2642,9 +2653,11 @@ class DocView extends ContentView {
2642
2653
  cView.flags |= 8 /* Composition */;
2643
2654
  this.markedForComposition.add(cView);
2644
2655
  let prev = ContentView.get(dom);
2645
- if (prev)
2646
- prev.dom = null;
2647
- cView.setDOM(dom);
2656
+ if (prev != cView) {
2657
+ if (prev)
2658
+ prev.dom = null;
2659
+ cView.setDOM(dom);
2660
+ }
2648
2661
  };
2649
2662
  let pos = this.childPos(composition.range.fromB, 1);
2650
2663
  let cView = this.children[pos.i];
@@ -3006,7 +3019,8 @@ function findCompositionRange(view, changes) {
3006
3019
  else
3007
3020
  return null;
3008
3021
  }
3009
- if (view.state.doc.sliceString(fromB, toB) != text)
3022
+ let { main } = view.state.selection;
3023
+ if (view.state.doc.sliceString(fromB, toB) != text || fromB > main.head || toB < main.head)
3010
3024
  return null;
3011
3025
  let marks = [];
3012
3026
  let range = new ChangedRange(fromA, toA, fromB, toB);
package/dist/index.js CHANGED
@@ -2496,7 +2496,7 @@ class DocView extends ContentView {
2496
2496
  this.view = view;
2497
2497
  this.decorations = [];
2498
2498
  this.dynamicDecorationMap = [];
2499
- this.hasComposition = false;
2499
+ this.hasComposition = null;
2500
2500
  this.markedForComposition = new Set;
2501
2501
  // Track a minimum width for the editor. When measuring sizes in
2502
2502
  // measureVisibleLineHeights, this is updated to point at the width
@@ -2536,9 +2536,13 @@ class DocView extends ContentView {
2536
2536
  }
2537
2537
  }
2538
2538
  let composition = this.view.inputState.composing < 0 ? null : findCompositionRange(this.view, update.changes);
2539
- if (this.hasComposition)
2539
+ if (this.hasComposition) {
2540
2540
  this.markedForComposition.clear();
2541
- this.hasComposition = !!composition;
2541
+ let { from, to } = this.hasComposition;
2542
+ changedRanges = new ChangedRange(from, to, update.changes.mapPos(from, -1), update.changes.mapPos(to, 1))
2543
+ .addToSet(changedRanges.slice());
2544
+ }
2545
+ this.hasComposition = composition ? { from: composition.range.fromB, to: composition.range.toB } : null;
2542
2546
  // When the DOM nodes around the selection are moved to another
2543
2547
  // parent, Chrome sometimes reports a different selection through
2544
2548
  // getSelection than the one that it actually shows to the user.
@@ -2607,9 +2611,16 @@ class DocView extends ContentView {
2607
2611
  openStart = before.openStart;
2608
2612
  openEnd = after.openEnd;
2609
2613
  let compLine = this.compositionView(composition);
2610
- compLine.merge(compLine.length, compLine.length, after.content[0], false, after.openStart, 0);
2611
- compLine.merge(0, 0, before.content[before.content.length - 1], true, 0, before.openEnd);
2612
- content = before.content.slice(0, before.content.length - 1).concat(compLine).concat(after.content.slice(1));
2614
+ if (after.content.length) {
2615
+ compLine.breakAfter = after.content[0].breakAfter;
2616
+ if (compLine.merge(compLine.length, compLine.length, after.content[0], false, after.openStart, 0))
2617
+ after.content.shift();
2618
+ }
2619
+ if (before.content.length) {
2620
+ if (compLine.merge(0, 0, before.content[before.content.length - 1], true, 0, before.openEnd))
2621
+ before.content.pop();
2622
+ }
2623
+ content = before.content.concat(compLine).concat(after.content);
2613
2624
  }
2614
2625
  else {
2615
2626
  ({ content, breakAtStart, openStart, openEnd } =
@@ -2636,9 +2647,11 @@ class DocView extends ContentView {
2636
2647
  cView.flags |= 8 /* Composition */;
2637
2648
  this.markedForComposition.add(cView);
2638
2649
  let prev = ContentView.get(dom);
2639
- if (prev)
2640
- prev.dom = null;
2641
- cView.setDOM(dom);
2650
+ if (prev != cView) {
2651
+ if (prev)
2652
+ prev.dom = null;
2653
+ cView.setDOM(dom);
2654
+ }
2642
2655
  };
2643
2656
  let pos = this.childPos(composition.range.fromB, 1);
2644
2657
  let cView = this.children[pos.i];
@@ -3000,7 +3013,8 @@ function findCompositionRange(view, changes) {
3000
3013
  else
3001
3014
  return null;
3002
3015
  }
3003
- if (view.state.doc.sliceString(fromB, toB) != text)
3016
+ let { main } = view.state.selection;
3017
+ if (view.state.doc.sliceString(fromB, toB) != text || fromB > main.head || toB < main.head)
3004
3018
  return null;
3005
3019
  let marks = [];
3006
3020
  let range = new ChangedRange(fromA, toA, fromB, toB);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "6.15.0",
3
+ "version": "6.15.2",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",