@codemirror/view 0.19.31 → 0.19.32

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,17 @@
1
+ ## 0.19.32 (2021-12-15)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix a bug where CodeMirror's own event handers would run even after a user-supplied handler called `preventDefault` on an event.
6
+
7
+ Properly draw selections when negative text-indent is used for soft wrapping.
8
+
9
+ Fix an issue where `viewportLineBlocks` could hold inaccurate height information when the vertical scaling changed.
10
+
11
+ Fixes drop cursor positioning when the document is scrolled. Force a content measure when the editor comes into view
12
+
13
+ Fix a bug that could cause the editor to not measure its layout the first time it came into view.
14
+
1
15
  ## 0.19.31 (2021-12-13)
2
16
 
3
17
  ### New features
package/dist/index.cjs CHANGED
@@ -3199,7 +3199,7 @@ class InputState {
3199
3199
  let handler = set.handlers[type];
3200
3200
  if (handler) {
3201
3201
  try {
3202
- if (handler.call(set.plugin, event, view))
3202
+ if (handler.call(set.plugin, event, view) || event.defaultPrevented)
3203
3203
  return true;
3204
3204
  }
3205
3205
  catch (e) {
@@ -4604,9 +4604,9 @@ class ViewState {
4604
4604
  let updateLines = !update.changes.empty || (update.flags & 2 /* Height */) ||
4605
4605
  viewport.from != this.viewport.from || viewport.to != this.viewport.to;
4606
4606
  this.viewport = viewport;
4607
+ this.updateForViewport();
4607
4608
  if (updateLines)
4608
4609
  this.updateViewportLines();
4609
- this.updateForViewport();
4610
4610
  if (this.lineGaps.length || this.viewport.to - this.viewport.from > 4000 /* DoubleMargin */)
4611
4611
  this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps, update.changes)));
4612
4612
  update.flags |= this.computeVisibleRanges();
@@ -4638,7 +4638,12 @@ class ViewState {
4638
4638
  let pixelViewport = this.printing ? { top: -1e8, bottom: 1e8, left: -1e8, right: 1e8 } : visiblePixelRange(dom, this.paddingTop);
4639
4639
  let dTop = pixelViewport.top - this.pixelViewport.top, dBottom = pixelViewport.bottom - this.pixelViewport.bottom;
4640
4640
  this.pixelViewport = pixelViewport;
4641
- this.inView = this.pixelViewport.bottom > this.pixelViewport.top && this.pixelViewport.right > this.pixelViewport.left;
4641
+ let inView = this.pixelViewport.bottom > this.pixelViewport.top && this.pixelViewport.right > this.pixelViewport.left;
4642
+ if (inView != this.inView) {
4643
+ this.inView = inView;
4644
+ if (inView)
4645
+ measureContent = true;
4646
+ }
4642
4647
  if (!this.inView)
4643
4648
  return 0;
4644
4649
  if (measureContent) {
@@ -4675,9 +4680,9 @@ class ViewState {
4675
4680
  this.scrollTarget && (this.scrollTarget.range.head < this.viewport.from || this.scrollTarget.range.head > this.viewport.to);
4676
4681
  if (viewportChange)
4677
4682
  this.viewport = this.getViewport(bias, this.scrollTarget);
4683
+ this.updateForViewport();
4678
4684
  if ((result & 2 /* Height */) || viewportChange)
4679
4685
  this.updateViewportLines();
4680
- this.updateForViewport();
4681
4686
  if (this.lineGaps.length || this.viewport.to - this.viewport.from > 4000 /* DoubleMargin */)
4682
4687
  this.updateLineGaps(this.ensureLineGaps(refresh ? [] : this.lineGaps));
4683
4688
  result |= this.computeVisibleRanges();
@@ -5213,7 +5218,7 @@ class DOMObserver {
5213
5218
  this.intersection = new IntersectionObserver(entries => {
5214
5219
  if (this.parentCheck < 0)
5215
5220
  this.parentCheck = setTimeout(this.listenForScroll.bind(this), 1000);
5216
- if (entries.length > 0 && entries[entries.length - 1].intersectionRatio > 0 != this.intersecting) {
5221
+ if (entries.length > 0 && (entries[entries.length - 1].intersectionRatio > 0) != this.intersecting) {
5217
5222
  this.intersecting = !this.intersecting;
5218
5223
  if (this.intersecting != this.view.inView)
5219
5224
  this.onScrollChanged(document.createEvent("Event"));
@@ -6907,7 +6912,7 @@ function measureRange(view, range) {
6907
6912
  let ltr = view.textDirection == exports.Direction.LTR;
6908
6913
  let content = view.contentDOM, contentRect = content.getBoundingClientRect(), base = getBase(view);
6909
6914
  let lineStyle = window.getComputedStyle(content.firstChild);
6910
- let leftSide = contentRect.left + parseInt(lineStyle.paddingLeft);
6915
+ let leftSide = contentRect.left + parseInt(lineStyle.paddingLeft) + Math.min(0, parseInt(lineStyle.textIndent));
6911
6916
  let rightSide = contentRect.right - parseInt(lineStyle.paddingRight);
6912
6917
  let startBlock = blockAt(view, from), endBlock = blockAt(view, to);
6913
6918
  let visualStart = startBlock.type == exports.BlockType.Text ? startBlock : null;
@@ -7033,7 +7038,11 @@ const drawDropCursor = ViewPlugin.fromClass(class {
7033
7038
  if (!rect)
7034
7039
  return null;
7035
7040
  let outer = this.view.scrollDOM.getBoundingClientRect();
7036
- return { left: rect.left - outer.left, top: rect.top - outer.top, height: rect.bottom - rect.top };
7041
+ return {
7042
+ left: rect.left - outer.left + this.view.scrollDOM.scrollLeft,
7043
+ top: rect.top - outer.top + this.view.scrollDOM.scrollTop,
7044
+ height: rect.bottom - rect.top
7045
+ };
7037
7046
  }
7038
7047
  drawCursor(pos) {
7039
7048
  if (this.cursor) {
package/dist/index.js CHANGED
@@ -3194,7 +3194,7 @@ class InputState {
3194
3194
  let handler = set.handlers[type];
3195
3195
  if (handler) {
3196
3196
  try {
3197
- if (handler.call(set.plugin, event, view))
3197
+ if (handler.call(set.plugin, event, view) || event.defaultPrevented)
3198
3198
  return true;
3199
3199
  }
3200
3200
  catch (e) {
@@ -4598,9 +4598,9 @@ class ViewState {
4598
4598
  let updateLines = !update.changes.empty || (update.flags & 2 /* Height */) ||
4599
4599
  viewport.from != this.viewport.from || viewport.to != this.viewport.to;
4600
4600
  this.viewport = viewport;
4601
+ this.updateForViewport();
4601
4602
  if (updateLines)
4602
4603
  this.updateViewportLines();
4603
- this.updateForViewport();
4604
4604
  if (this.lineGaps.length || this.viewport.to - this.viewport.from > 4000 /* DoubleMargin */)
4605
4605
  this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps, update.changes)));
4606
4606
  update.flags |= this.computeVisibleRanges();
@@ -4632,7 +4632,12 @@ class ViewState {
4632
4632
  let pixelViewport = this.printing ? { top: -1e8, bottom: 1e8, left: -1e8, right: 1e8 } : visiblePixelRange(dom, this.paddingTop);
4633
4633
  let dTop = pixelViewport.top - this.pixelViewport.top, dBottom = pixelViewport.bottom - this.pixelViewport.bottom;
4634
4634
  this.pixelViewport = pixelViewport;
4635
- this.inView = this.pixelViewport.bottom > this.pixelViewport.top && this.pixelViewport.right > this.pixelViewport.left;
4635
+ let inView = this.pixelViewport.bottom > this.pixelViewport.top && this.pixelViewport.right > this.pixelViewport.left;
4636
+ if (inView != this.inView) {
4637
+ this.inView = inView;
4638
+ if (inView)
4639
+ measureContent = true;
4640
+ }
4636
4641
  if (!this.inView)
4637
4642
  return 0;
4638
4643
  if (measureContent) {
@@ -4669,9 +4674,9 @@ class ViewState {
4669
4674
  this.scrollTarget && (this.scrollTarget.range.head < this.viewport.from || this.scrollTarget.range.head > this.viewport.to);
4670
4675
  if (viewportChange)
4671
4676
  this.viewport = this.getViewport(bias, this.scrollTarget);
4677
+ this.updateForViewport();
4672
4678
  if ((result & 2 /* Height */) || viewportChange)
4673
4679
  this.updateViewportLines();
4674
- this.updateForViewport();
4675
4680
  if (this.lineGaps.length || this.viewport.to - this.viewport.from > 4000 /* DoubleMargin */)
4676
4681
  this.updateLineGaps(this.ensureLineGaps(refresh ? [] : this.lineGaps));
4677
4682
  result |= this.computeVisibleRanges();
@@ -5207,7 +5212,7 @@ class DOMObserver {
5207
5212
  this.intersection = new IntersectionObserver(entries => {
5208
5213
  if (this.parentCheck < 0)
5209
5214
  this.parentCheck = setTimeout(this.listenForScroll.bind(this), 1000);
5210
- if (entries.length > 0 && entries[entries.length - 1].intersectionRatio > 0 != this.intersecting) {
5215
+ if (entries.length > 0 && (entries[entries.length - 1].intersectionRatio > 0) != this.intersecting) {
5211
5216
  this.intersecting = !this.intersecting;
5212
5217
  if (this.intersecting != this.view.inView)
5213
5218
  this.onScrollChanged(document.createEvent("Event"));
@@ -6901,7 +6906,7 @@ function measureRange(view, range) {
6901
6906
  let ltr = view.textDirection == Direction.LTR;
6902
6907
  let content = view.contentDOM, contentRect = content.getBoundingClientRect(), base = getBase(view);
6903
6908
  let lineStyle = window.getComputedStyle(content.firstChild);
6904
- let leftSide = contentRect.left + parseInt(lineStyle.paddingLeft);
6909
+ let leftSide = contentRect.left + parseInt(lineStyle.paddingLeft) + Math.min(0, parseInt(lineStyle.textIndent));
6905
6910
  let rightSide = contentRect.right - parseInt(lineStyle.paddingRight);
6906
6911
  let startBlock = blockAt(view, from), endBlock = blockAt(view, to);
6907
6912
  let visualStart = startBlock.type == BlockType.Text ? startBlock : null;
@@ -7027,7 +7032,11 @@ const drawDropCursor = /*@__PURE__*/ViewPlugin.fromClass(class {
7027
7032
  if (!rect)
7028
7033
  return null;
7029
7034
  let outer = this.view.scrollDOM.getBoundingClientRect();
7030
- return { left: rect.left - outer.left, top: rect.top - outer.top, height: rect.bottom - rect.top };
7035
+ return {
7036
+ left: rect.left - outer.left + this.view.scrollDOM.scrollLeft,
7037
+ top: rect.top - outer.top + this.view.scrollDOM.scrollTop,
7038
+ height: rect.bottom - rect.top
7039
+ };
7031
7040
  }
7032
7041
  drawCursor(pos) {
7033
7042
  if (this.cursor) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "0.19.31",
3
+ "version": "0.19.32",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",
@@ -26,7 +26,7 @@
26
26
  "sideEffects": false,
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
- "@codemirror/rangeset": "^0.19.0",
29
+ "@codemirror/rangeset": "^0.19.4",
30
30
  "@codemirror/state": "^0.19.3",
31
31
  "@codemirror/text": "^0.19.0",
32
32
  "style-mod": "^4.0.0",