@codemirror/view 6.4.1 → 6.5.0
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 +20 -0
- package/dist/index.cjs +16 -13
- package/dist/index.d.ts +5 -8
- package/dist/index.js +17 -14
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
## 6.5.0 (2022-11-14)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Fix an issue where key bindings were activated for the wrong key in some situations with non-US keyboards.
|
|
6
|
+
|
|
7
|
+
### New features
|
|
8
|
+
|
|
9
|
+
A tooltip's `positioned` callback is now passed the available space for tooltips.
|
|
10
|
+
|
|
11
|
+
## 6.4.2 (2022-11-10)
|
|
12
|
+
|
|
13
|
+
### Bug fixes
|
|
14
|
+
|
|
15
|
+
Typing into a read-only editor no longer moves the cursor.
|
|
16
|
+
|
|
17
|
+
Fix an issue where hover tooltips were closed when the mouse was moved over them if they had a custom parent element.
|
|
18
|
+
|
|
19
|
+
Fix an issue where the editor could end up displaying incorrect height measurements (typically after initializing).
|
|
20
|
+
|
|
1
21
|
## 6.4.1 (2022-11-07)
|
|
2
22
|
|
|
3
23
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -4038,9 +4038,9 @@ handlers.beforeinput = (view, event) => {
|
|
|
4038
4038
|
|
|
4039
4039
|
const wrappingWhiteSpace = ["pre-wrap", "normal", "pre-line", "break-spaces"];
|
|
4040
4040
|
class HeightOracle {
|
|
4041
|
-
constructor() {
|
|
4041
|
+
constructor(lineWrapping) {
|
|
4042
|
+
this.lineWrapping = lineWrapping;
|
|
4042
4043
|
this.doc = state.Text.empty;
|
|
4043
|
-
this.lineWrapping = false;
|
|
4044
4044
|
this.heightSamples = {};
|
|
4045
4045
|
this.lineHeight = 14;
|
|
4046
4046
|
this.charWidth = 7;
|
|
@@ -4780,7 +4780,6 @@ class ViewState {
|
|
|
4780
4780
|
this.contentDOMHeight = 0;
|
|
4781
4781
|
this.editorHeight = 0;
|
|
4782
4782
|
this.editorWidth = 0;
|
|
4783
|
-
this.heightOracle = new HeightOracle;
|
|
4784
4783
|
// See VP.MaxDOMHeight
|
|
4785
4784
|
this.scaler = IdScaler;
|
|
4786
4785
|
this.scrollTarget = null;
|
|
@@ -4800,6 +4799,8 @@ class ViewState {
|
|
|
4800
4799
|
// boundary and, if so, reset it to make sure it is positioned in
|
|
4801
4800
|
// the right place.
|
|
4802
4801
|
this.mustEnforceCursorAssoc = false;
|
|
4802
|
+
let guessWrapping = state$1.facet(contentAttributes).some(v => typeof v != "function" && v.class == "cm-lineWrapping");
|
|
4803
|
+
this.heightOracle = new HeightOracle(guessWrapping);
|
|
4803
4804
|
this.stateDeco = state$1.facet(decorations).filter(d => typeof d != "function");
|
|
4804
4805
|
this.heightMap = HeightMap.empty().applyChanges(this.stateDeco, state.Text.empty, this.heightOracle.setDoc(state$1.doc), [new ChangedRange(0, 0, 0, state$1.doc.length)]);
|
|
4805
4806
|
this.viewport = this.getViewport(0, null);
|
|
@@ -4918,9 +4919,7 @@ class ViewState {
|
|
|
4918
4919
|
oracle.heightChanged = false;
|
|
4919
4920
|
for (let vp of this.viewports) {
|
|
4920
4921
|
let heights = vp.from == this.viewport.from ? lineHeights : view.docView.measureVisibleLineHeights(vp);
|
|
4921
|
-
this.heightMap = refresh
|
|
4922
|
-
? HeightMap.empty().applyChanges(this.stateDeco, state.Text.empty, this.heightOracle, [new ChangedRange(0, 0, 0, view.state.doc.length)])
|
|
4923
|
-
: this.heightMap.updateHeight(oracle, 0, refresh, new MeasuredHeights(vp.from, heights));
|
|
4922
|
+
this.heightMap = (refresh ? HeightMap.empty().applyChanges(this.stateDeco, state.Text.empty, this.heightOracle, [new ChangedRange(0, 0, 0, view.state.doc.length)]) : this.heightMap).updateHeight(oracle, 0, refresh, new MeasuredHeights(vp.from, heights));
|
|
4924
4923
|
}
|
|
4925
4924
|
if (oracle.heightChanged)
|
|
4926
4925
|
result |= 2 /* UpdateFlag.Height */;
|
|
@@ -5486,7 +5485,11 @@ class DOMChange {
|
|
|
5486
5485
|
this.bounds = null;
|
|
5487
5486
|
this.text = "";
|
|
5488
5487
|
let { impreciseHead: iHead, impreciseAnchor: iAnchor } = view.docView;
|
|
5489
|
-
if (
|
|
5488
|
+
if (view.state.readOnly && start > -1) {
|
|
5489
|
+
// Ignore changes when the editor is read-only
|
|
5490
|
+
this.newSel = null;
|
|
5491
|
+
}
|
|
5492
|
+
else if (start > -1 && (this.bounds = view.docView.domBoundsAround(start, end, 0))) {
|
|
5490
5493
|
let selPoints = iHead || iAnchor ? [] : selectionPoints(view);
|
|
5491
5494
|
let reader = new DOMReader(selPoints, view.state);
|
|
5492
5495
|
reader.readRange(this.bounds.startDOM, this.bounds.endDOM);
|
|
@@ -7273,7 +7276,7 @@ function runHandlers(map, event, view, scope) {
|
|
|
7273
7276
|
if (scopeObj) {
|
|
7274
7277
|
if (runFor(scopeObj[prefix + modifiers(name, event, !isChar)]))
|
|
7275
7278
|
return true;
|
|
7276
|
-
if (isChar && (event.
|
|
7279
|
+
if (isChar && (event.altKey || event.metaKey || event.ctrlKey) &&
|
|
7277
7280
|
(baseName = w3cKeyname.base[event.keyCode]) && baseName != name) {
|
|
7278
7281
|
if (runFor(scopeObj[prefix + modifiers(baseName, event, true)]))
|
|
7279
7282
|
return true;
|
|
@@ -8354,7 +8357,7 @@ const tooltipPlugin = ViewPlugin.fromClass(class {
|
|
|
8354
8357
|
dom.classList.toggle("cm-tooltip-above", above);
|
|
8355
8358
|
dom.classList.toggle("cm-tooltip-below", !above);
|
|
8356
8359
|
if (tView.positioned)
|
|
8357
|
-
tView.positioned();
|
|
8360
|
+
tView.positioned(measured.space);
|
|
8358
8361
|
}
|
|
8359
8362
|
}
|
|
8360
8363
|
maybeMeasure() {
|
|
@@ -8470,10 +8473,10 @@ class HoverTooltipHost {
|
|
|
8470
8473
|
}
|
|
8471
8474
|
this.mounted = true;
|
|
8472
8475
|
}
|
|
8473
|
-
positioned() {
|
|
8476
|
+
positioned(space) {
|
|
8474
8477
|
for (let hostedView of this.manager.tooltipViews) {
|
|
8475
8478
|
if (hostedView.positioned)
|
|
8476
|
-
hostedView.positioned();
|
|
8479
|
+
hostedView.positioned(space);
|
|
8477
8480
|
}
|
|
8478
8481
|
}
|
|
8479
8482
|
update(update) {
|
|
@@ -8570,10 +8573,10 @@ class HoverPlugin {
|
|
|
8570
8573
|
}
|
|
8571
8574
|
}
|
|
8572
8575
|
}
|
|
8573
|
-
mouseleave() {
|
|
8576
|
+
mouseleave(e) {
|
|
8574
8577
|
clearTimeout(this.hoverTimeout);
|
|
8575
8578
|
this.hoverTimeout = -1;
|
|
8576
|
-
if (this.active)
|
|
8579
|
+
if (this.active && !isInTooltip(e.relatedTarget))
|
|
8577
8580
|
this.view.dispatch({ effects: this.setHover.of(null) });
|
|
8578
8581
|
}
|
|
8579
8582
|
destroy() {
|
package/dist/index.d.ts
CHANGED
|
@@ -1491,12 +1491,7 @@ declare function tooltips(config?: {
|
|
|
1491
1491
|
for showing tooltips. You can provide a function here that
|
|
1492
1492
|
returns an alternative rectangle.
|
|
1493
1493
|
*/
|
|
1494
|
-
tooltipSpace?: (view: EditorView) =>
|
|
1495
|
-
top: number;
|
|
1496
|
-
left: number;
|
|
1497
|
-
bottom: number;
|
|
1498
|
-
right: number;
|
|
1499
|
-
};
|
|
1494
|
+
tooltipSpace?: (view: EditorView) => Rect;
|
|
1500
1495
|
}): Extension;
|
|
1501
1496
|
/**
|
|
1502
1497
|
Describes a tooltip. Values of this type, when provided through
|
|
@@ -1584,9 +1579,11 @@ interface TooltipView {
|
|
|
1584
1579
|
*/
|
|
1585
1580
|
destroy?(): void;
|
|
1586
1581
|
/**
|
|
1587
|
-
Called when the tooltip has been (re)positioned.
|
|
1582
|
+
Called when the tooltip has been (re)positioned. The argument is
|
|
1583
|
+
the [space](https://codemirror.net/6/docs/ref/#view.tooltips^config.tooltipSpace) available to the
|
|
1584
|
+
tooltip.
|
|
1588
1585
|
*/
|
|
1589
|
-
positioned?(): void;
|
|
1586
|
+
positioned?(space: Rect): void;
|
|
1590
1587
|
}
|
|
1591
1588
|
/**
|
|
1592
1589
|
Facet to which an extension can add a value to show a tooltip.
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Text, RangeSet, MapMode, RangeValue, Facet, StateEffect, ChangeSet, findClusterBreak, EditorSelection, EditorState, findColumn, CharCategory,
|
|
1
|
+
import { Text, RangeSet, MapMode, RangeValue, Facet, StateEffect, ChangeSet, findClusterBreak, EditorSelection, EditorState, findColumn, CharCategory, Transaction, Prec, codePointAt, codePointSize, combineConfig, StateField, RangeSetBuilder, countColumn } from '@codemirror/state';
|
|
2
2
|
import { StyleModule } from 'style-mod';
|
|
3
3
|
import { keyName, base, shift } from 'w3c-keyname';
|
|
4
4
|
|
|
@@ -4032,9 +4032,9 @@ handlers.beforeinput = (view, event) => {
|
|
|
4032
4032
|
|
|
4033
4033
|
const wrappingWhiteSpace = ["pre-wrap", "normal", "pre-line", "break-spaces"];
|
|
4034
4034
|
class HeightOracle {
|
|
4035
|
-
constructor() {
|
|
4035
|
+
constructor(lineWrapping) {
|
|
4036
|
+
this.lineWrapping = lineWrapping;
|
|
4036
4037
|
this.doc = Text.empty;
|
|
4037
|
-
this.lineWrapping = false;
|
|
4038
4038
|
this.heightSamples = {};
|
|
4039
4039
|
this.lineHeight = 14;
|
|
4040
4040
|
this.charWidth = 7;
|
|
@@ -4773,7 +4773,6 @@ class ViewState {
|
|
|
4773
4773
|
this.contentDOMHeight = 0;
|
|
4774
4774
|
this.editorHeight = 0;
|
|
4775
4775
|
this.editorWidth = 0;
|
|
4776
|
-
this.heightOracle = new HeightOracle;
|
|
4777
4776
|
// See VP.MaxDOMHeight
|
|
4778
4777
|
this.scaler = IdScaler;
|
|
4779
4778
|
this.scrollTarget = null;
|
|
@@ -4793,6 +4792,8 @@ class ViewState {
|
|
|
4793
4792
|
// boundary and, if so, reset it to make sure it is positioned in
|
|
4794
4793
|
// the right place.
|
|
4795
4794
|
this.mustEnforceCursorAssoc = false;
|
|
4795
|
+
let guessWrapping = state.facet(contentAttributes).some(v => typeof v != "function" && v.class == "cm-lineWrapping");
|
|
4796
|
+
this.heightOracle = new HeightOracle(guessWrapping);
|
|
4796
4797
|
this.stateDeco = state.facet(decorations).filter(d => typeof d != "function");
|
|
4797
4798
|
this.heightMap = HeightMap.empty().applyChanges(this.stateDeco, Text.empty, this.heightOracle.setDoc(state.doc), [new ChangedRange(0, 0, 0, state.doc.length)]);
|
|
4798
4799
|
this.viewport = this.getViewport(0, null);
|
|
@@ -4911,9 +4912,7 @@ class ViewState {
|
|
|
4911
4912
|
oracle.heightChanged = false;
|
|
4912
4913
|
for (let vp of this.viewports) {
|
|
4913
4914
|
let heights = vp.from == this.viewport.from ? lineHeights : view.docView.measureVisibleLineHeights(vp);
|
|
4914
|
-
this.heightMap = refresh
|
|
4915
|
-
? HeightMap.empty().applyChanges(this.stateDeco, Text.empty, this.heightOracle, [new ChangedRange(0, 0, 0, view.state.doc.length)])
|
|
4916
|
-
: this.heightMap.updateHeight(oracle, 0, refresh, new MeasuredHeights(vp.from, heights));
|
|
4915
|
+
this.heightMap = (refresh ? HeightMap.empty().applyChanges(this.stateDeco, Text.empty, this.heightOracle, [new ChangedRange(0, 0, 0, view.state.doc.length)]) : this.heightMap).updateHeight(oracle, 0, refresh, new MeasuredHeights(vp.from, heights));
|
|
4917
4916
|
}
|
|
4918
4917
|
if (oracle.heightChanged)
|
|
4919
4918
|
result |= 2 /* UpdateFlag.Height */;
|
|
@@ -5479,7 +5478,11 @@ class DOMChange {
|
|
|
5479
5478
|
this.bounds = null;
|
|
5480
5479
|
this.text = "";
|
|
5481
5480
|
let { impreciseHead: iHead, impreciseAnchor: iAnchor } = view.docView;
|
|
5482
|
-
if (
|
|
5481
|
+
if (view.state.readOnly && start > -1) {
|
|
5482
|
+
// Ignore changes when the editor is read-only
|
|
5483
|
+
this.newSel = null;
|
|
5484
|
+
}
|
|
5485
|
+
else if (start > -1 && (this.bounds = view.docView.domBoundsAround(start, end, 0))) {
|
|
5483
5486
|
let selPoints = iHead || iAnchor ? [] : selectionPoints(view);
|
|
5484
5487
|
let reader = new DOMReader(selPoints, view.state);
|
|
5485
5488
|
reader.readRange(this.bounds.startDOM, this.bounds.endDOM);
|
|
@@ -7266,7 +7269,7 @@ function runHandlers(map, event, view, scope) {
|
|
|
7266
7269
|
if (scopeObj) {
|
|
7267
7270
|
if (runFor(scopeObj[prefix + modifiers(name, event, !isChar)]))
|
|
7268
7271
|
return true;
|
|
7269
|
-
if (isChar && (event.
|
|
7272
|
+
if (isChar && (event.altKey || event.metaKey || event.ctrlKey) &&
|
|
7270
7273
|
(baseName = base[event.keyCode]) && baseName != name) {
|
|
7271
7274
|
if (runFor(scopeObj[prefix + modifiers(baseName, event, true)]))
|
|
7272
7275
|
return true;
|
|
@@ -8347,7 +8350,7 @@ const tooltipPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
|
8347
8350
|
dom.classList.toggle("cm-tooltip-above", above);
|
|
8348
8351
|
dom.classList.toggle("cm-tooltip-below", !above);
|
|
8349
8352
|
if (tView.positioned)
|
|
8350
|
-
tView.positioned();
|
|
8353
|
+
tView.positioned(measured.space);
|
|
8351
8354
|
}
|
|
8352
8355
|
}
|
|
8353
8356
|
maybeMeasure() {
|
|
@@ -8463,10 +8466,10 @@ class HoverTooltipHost {
|
|
|
8463
8466
|
}
|
|
8464
8467
|
this.mounted = true;
|
|
8465
8468
|
}
|
|
8466
|
-
positioned() {
|
|
8469
|
+
positioned(space) {
|
|
8467
8470
|
for (let hostedView of this.manager.tooltipViews) {
|
|
8468
8471
|
if (hostedView.positioned)
|
|
8469
|
-
hostedView.positioned();
|
|
8472
|
+
hostedView.positioned(space);
|
|
8470
8473
|
}
|
|
8471
8474
|
}
|
|
8472
8475
|
update(update) {
|
|
@@ -8563,10 +8566,10 @@ class HoverPlugin {
|
|
|
8563
8566
|
}
|
|
8564
8567
|
}
|
|
8565
8568
|
}
|
|
8566
|
-
mouseleave() {
|
|
8569
|
+
mouseleave(e) {
|
|
8567
8570
|
clearTimeout(this.hoverTimeout);
|
|
8568
8571
|
this.hoverTimeout = -1;
|
|
8569
|
-
if (this.active)
|
|
8572
|
+
if (this.active && !isInTooltip(e.relatedTarget))
|
|
8570
8573
|
this.view.dispatch({ effects: this.setHover.of(null) });
|
|
8571
8574
|
}
|
|
8572
8575
|
destroy() {
|