@codemirror/view 6.28.6 → 6.29.1
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 +48 -30
- package/dist/index.d.cts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +48 -30
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
## 6.29.1 (2024-07-29)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Fix a crash on old Safari browsers that don't support `MediaQueryList.addEventListener`.
|
|
6
|
+
|
|
7
|
+
Fix an issue where `EditorView.viewportLineBlocks` (and thus other things like the gutter) might be out of date after some kinds of decoration changes.
|
|
8
|
+
|
|
9
|
+
## 6.29.0 (2024-07-25)
|
|
10
|
+
|
|
11
|
+
### Bug fixes
|
|
12
|
+
|
|
13
|
+
Fix an issue that caused typing into an editor marked read-only to cause document changes when using `EditContext`.
|
|
14
|
+
|
|
15
|
+
Associate a cursor created by clicking above the end of the text on a wrap point with the line before it.
|
|
16
|
+
|
|
17
|
+
### New features
|
|
18
|
+
|
|
19
|
+
The package now exports the type of hover tooltip sources as `HoverTooltipSource`.
|
|
20
|
+
|
|
1
21
|
## 6.28.6 (2024-07-19)
|
|
2
22
|
|
|
3
23
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -4252,8 +4252,7 @@ function rangeForClick(view, pos, bias, type) {
|
|
|
4252
4252
|
return state.EditorSelection.range(from, to);
|
|
4253
4253
|
}
|
|
4254
4254
|
}
|
|
4255
|
-
let
|
|
4256
|
-
let inside = (x, y, rect) => insideY(y, rect) && x >= rect.left && x <= rect.right;
|
|
4255
|
+
let inside = (x, y, rect) => y >= rect.top && y <= rect.bottom && x >= rect.left && x <= rect.right;
|
|
4257
4256
|
// Try to determine, for the given coordinates, associated with the
|
|
4258
4257
|
// given position, whether they are related to the element before or
|
|
4259
4258
|
// the element after the position.
|
|
@@ -4275,8 +4274,8 @@ function findPositionSide(view, pos, x, y) {
|
|
|
4275
4274
|
if (after && inside(x, y, after))
|
|
4276
4275
|
return 1;
|
|
4277
4276
|
// This is probably a line wrap point. Pick before if the point is
|
|
4278
|
-
//
|
|
4279
|
-
return before &&
|
|
4277
|
+
// above its bottom.
|
|
4278
|
+
return before && before.bottom >= y ? -1 : 1;
|
|
4280
4279
|
}
|
|
4281
4280
|
function queryPos(view, event) {
|
|
4282
4281
|
let pos = view.posAtCoords({ x: event.clientX, y: event.clientY }, false);
|
|
@@ -4606,6 +4605,9 @@ function firefoxCopyCutHack(doc) {
|
|
|
4606
4605
|
}
|
|
4607
4606
|
|
|
4608
4607
|
const wrappingWhiteSpace = ["pre-wrap", "normal", "pre-line", "break-spaces"];
|
|
4608
|
+
// Used to track, during updateHeight, if any actual heights changed
|
|
4609
|
+
let heightChangeFlag = false;
|
|
4610
|
+
function clearHeightChangeFlag() { heightChangeFlag = false; }
|
|
4609
4611
|
class HeightOracle {
|
|
4610
4612
|
constructor(lineWrapping) {
|
|
4611
4613
|
this.lineWrapping = lineWrapping;
|
|
@@ -4615,8 +4617,6 @@ class HeightOracle {
|
|
|
4615
4617
|
this.charWidth = 7;
|
|
4616
4618
|
this.textHeight = 14; // The height of the actual font (font-size)
|
|
4617
4619
|
this.lineLength = 30;
|
|
4618
|
-
// Used to track, during updateHeight, if any actual heights changed
|
|
4619
|
-
this.heightChanged = false;
|
|
4620
4620
|
}
|
|
4621
4621
|
heightForGap(from, to) {
|
|
4622
4622
|
let lines = this.doc.lineAt(to).number - this.doc.lineAt(from).number + 1;
|
|
@@ -4775,10 +4775,10 @@ class HeightMap {
|
|
|
4775
4775
|
}
|
|
4776
4776
|
get outdated() { return (this.flags & 2 /* Flag.Outdated */) > 0; }
|
|
4777
4777
|
set outdated(value) { this.flags = (value ? 2 /* Flag.Outdated */ : 0) | (this.flags & ~2 /* Flag.Outdated */); }
|
|
4778
|
-
setHeight(
|
|
4778
|
+
setHeight(height) {
|
|
4779
4779
|
if (this.height != height) {
|
|
4780
4780
|
if (Math.abs(this.height - height) > Epsilon)
|
|
4781
|
-
|
|
4781
|
+
heightChangeFlag = true;
|
|
4782
4782
|
this.height = height;
|
|
4783
4783
|
}
|
|
4784
4784
|
}
|
|
@@ -4809,7 +4809,7 @@ class HeightMap {
|
|
|
4809
4809
|
fromB += start.from - fromA;
|
|
4810
4810
|
fromA = start.from;
|
|
4811
4811
|
let nodes = NodeBuilder.build(oracle.setDoc(doc), decorations, fromB, toB);
|
|
4812
|
-
me = me.replace(fromA, toA, nodes);
|
|
4812
|
+
me = replace(me, me.replace(fromA, toA, nodes));
|
|
4813
4813
|
}
|
|
4814
4814
|
return me.updateHeight(oracle, 0);
|
|
4815
4815
|
}
|
|
@@ -4869,6 +4869,13 @@ class HeightMap {
|
|
|
4869
4869
|
return new HeightMapBranch(HeightMap.of(nodes.slice(0, i)), brk, HeightMap.of(nodes.slice(j)));
|
|
4870
4870
|
}
|
|
4871
4871
|
}
|
|
4872
|
+
function replace(old, val) {
|
|
4873
|
+
if (old == val)
|
|
4874
|
+
return old;
|
|
4875
|
+
if (old.constructor != val.constructor)
|
|
4876
|
+
heightChangeFlag = true;
|
|
4877
|
+
return val;
|
|
4878
|
+
}
|
|
4872
4879
|
HeightMap.prototype.size = 1;
|
|
4873
4880
|
class HeightMapBlock extends HeightMap {
|
|
4874
4881
|
constructor(length, height, deco) {
|
|
@@ -4887,7 +4894,7 @@ class HeightMapBlock extends HeightMap {
|
|
|
4887
4894
|
}
|
|
4888
4895
|
updateHeight(oracle, offset = 0, _force = false, measured) {
|
|
4889
4896
|
if (measured && measured.from <= offset && measured.more)
|
|
4890
|
-
this.setHeight(
|
|
4897
|
+
this.setHeight(measured.heights[measured.index++]);
|
|
4891
4898
|
this.outdated = false;
|
|
4892
4899
|
return this;
|
|
4893
4900
|
}
|
|
@@ -4921,9 +4928,9 @@ class HeightMapText extends HeightMapBlock {
|
|
|
4921
4928
|
}
|
|
4922
4929
|
updateHeight(oracle, offset = 0, force = false, measured) {
|
|
4923
4930
|
if (measured && measured.from <= offset && measured.more)
|
|
4924
|
-
this.setHeight(
|
|
4931
|
+
this.setHeight(measured.heights[measured.index++]);
|
|
4925
4932
|
else if (force || this.outdated)
|
|
4926
|
-
this.setHeight(
|
|
4933
|
+
this.setHeight(Math.max(this.widgetHeight, oracle.heightForLine(this.length - this.collapsed)) +
|
|
4927
4934
|
this.breaks * oracle.lineHeight);
|
|
4928
4935
|
this.outdated = false;
|
|
4929
4936
|
return this;
|
|
@@ -5046,11 +5053,11 @@ class HeightMapGap extends HeightMap {
|
|
|
5046
5053
|
let result = HeightMap.of(nodes);
|
|
5047
5054
|
if (singleHeight < 0 || Math.abs(result.height - this.height) >= Epsilon ||
|
|
5048
5055
|
Math.abs(singleHeight - this.heightMetrics(oracle, offset).perLine) >= Epsilon)
|
|
5049
|
-
|
|
5050
|
-
return result;
|
|
5056
|
+
heightChangeFlag = true;
|
|
5057
|
+
return replace(this, result);
|
|
5051
5058
|
}
|
|
5052
5059
|
else if (force || this.outdated) {
|
|
5053
|
-
this.setHeight(oracle
|
|
5060
|
+
this.setHeight(oracle.heightForGap(offset, offset + this.length));
|
|
5054
5061
|
this.outdated = false;
|
|
5055
5062
|
}
|
|
5056
5063
|
return this;
|
|
@@ -5148,9 +5155,9 @@ class HeightMapBranch extends HeightMap {
|
|
|
5148
5155
|
balanced(left, right) {
|
|
5149
5156
|
if (left.size > 2 * right.size || right.size > 2 * left.size)
|
|
5150
5157
|
return HeightMap.of(this.break ? [left, null, right] : [left, right]);
|
|
5151
|
-
this.left = left;
|
|
5152
|
-
this.right = right;
|
|
5153
|
-
this.
|
|
5158
|
+
this.left = replace(this.left, left);
|
|
5159
|
+
this.right = replace(this.right, right);
|
|
5160
|
+
this.setHeight(left.height + right.height);
|
|
5154
5161
|
this.outdated = left.outdated || right.outdated;
|
|
5155
5162
|
this.size = left.size + right.size;
|
|
5156
5163
|
this.length = left.length + this.break + right.length;
|
|
@@ -5489,8 +5496,9 @@ class ViewState {
|
|
|
5489
5496
|
let heightChanges = ChangedRange.extendWithRanges(contentChanges, heightRelevantDecoChanges(prevDeco, this.stateDeco, update ? update.changes : state.ChangeSet.empty(this.state.doc.length)));
|
|
5490
5497
|
let prevHeight = this.heightMap.height;
|
|
5491
5498
|
let scrollAnchor = this.scrolledToBottom ? null : this.scrollAnchorAt(this.scrollTop);
|
|
5499
|
+
clearHeightChangeFlag();
|
|
5492
5500
|
this.heightMap = this.heightMap.applyChanges(this.stateDeco, update.startState.doc, this.heightOracle.setDoc(this.state.doc), heightChanges);
|
|
5493
|
-
if (this.heightMap.height != prevHeight)
|
|
5501
|
+
if (this.heightMap.height != prevHeight || heightChangeFlag)
|
|
5494
5502
|
update.flags |= 2 /* UpdateFlag.Height */;
|
|
5495
5503
|
if (scrollAnchor) {
|
|
5496
5504
|
this.scrollAnchorPos = update.changes.mapPos(scrollAnchor.from, -1);
|
|
@@ -5594,12 +5602,12 @@ class ViewState {
|
|
|
5594
5602
|
bias = Math.max(dTop, dBottom);
|
|
5595
5603
|
else if (dTop < 0 && dBottom < 0)
|
|
5596
5604
|
bias = Math.min(dTop, dBottom);
|
|
5597
|
-
|
|
5605
|
+
clearHeightChangeFlag();
|
|
5598
5606
|
for (let vp of this.viewports) {
|
|
5599
5607
|
let heights = vp.from == this.viewport.from ? lineHeights : view.docView.measureVisibleLineHeights(vp);
|
|
5600
5608
|
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));
|
|
5601
5609
|
}
|
|
5602
|
-
if (
|
|
5610
|
+
if (heightChangeFlag)
|
|
5603
5611
|
result |= 2 /* UpdateFlag.Height */;
|
|
5604
5612
|
}
|
|
5605
5613
|
let viewportChange = !this.viewportIsAppropriate(this.viewport, bias) ||
|
|
@@ -6719,7 +6727,7 @@ class DOMObserver {
|
|
|
6719
6727
|
}, 50);
|
|
6720
6728
|
}
|
|
6721
6729
|
onPrint(event) {
|
|
6722
|
-
if (event.type == "change" && !event.matches)
|
|
6730
|
+
if ((event.type == "change" || !event.type) && !event.matches)
|
|
6723
6731
|
return;
|
|
6724
6732
|
this.view.viewState.printing = true;
|
|
6725
6733
|
this.view.measure();
|
|
@@ -7002,8 +7010,12 @@ class DOMObserver {
|
|
|
7002
7010
|
}
|
|
7003
7011
|
addWindowListeners(win) {
|
|
7004
7012
|
win.addEventListener("resize", this.onResize);
|
|
7005
|
-
if (this.printQuery)
|
|
7006
|
-
this.printQuery.addEventListener
|
|
7013
|
+
if (this.printQuery) {
|
|
7014
|
+
if (this.printQuery.addEventListener)
|
|
7015
|
+
this.printQuery.addEventListener("change", this.onPrint);
|
|
7016
|
+
else
|
|
7017
|
+
this.printQuery.addListener(this.onPrint);
|
|
7018
|
+
}
|
|
7007
7019
|
else
|
|
7008
7020
|
win.addEventListener("beforeprint", this.onPrint);
|
|
7009
7021
|
win.addEventListener("scroll", this.onScroll);
|
|
@@ -7012,8 +7024,12 @@ class DOMObserver {
|
|
|
7012
7024
|
removeWindowListeners(win) {
|
|
7013
7025
|
win.removeEventListener("scroll", this.onScroll);
|
|
7014
7026
|
win.removeEventListener("resize", this.onResize);
|
|
7015
|
-
if (this.printQuery)
|
|
7016
|
-
this.printQuery.removeEventListener
|
|
7027
|
+
if (this.printQuery) {
|
|
7028
|
+
if (this.printQuery.removeEventListener)
|
|
7029
|
+
this.printQuery.removeEventListener("change", this.onPrint);
|
|
7030
|
+
else
|
|
7031
|
+
this.printQuery.removeListener(this.onPrint);
|
|
7032
|
+
}
|
|
7017
7033
|
else
|
|
7018
7034
|
win.removeEventListener("beforeprint", this.onPrint);
|
|
7019
7035
|
win.document.removeEventListener("selectionchange", this.onSelectionChange);
|
|
@@ -7123,7 +7139,8 @@ class EditContextManager {
|
|
|
7123
7139
|
if (change.from == change.to && !change.insert.length)
|
|
7124
7140
|
return;
|
|
7125
7141
|
this.pendingContextChange = change;
|
|
7126
|
-
|
|
7142
|
+
if (!view.state.readOnly)
|
|
7143
|
+
applyDOMChangeInner(view, change, state.EditorSelection.single(this.toEditorPos(e.selectionStart), this.toEditorPos(e.selectionEnd)));
|
|
7127
7144
|
// If the transaction didn't flush our change, revert it so
|
|
7128
7145
|
// that the context is in sync with the editor state again.
|
|
7129
7146
|
if (this.pendingContextChange) {
|
|
@@ -9866,9 +9883,10 @@ const tooltipPlugin = ViewPlugin.fromClass(class {
|
|
|
9866
9883
|
let arrowHeight = arrow ? 7 /* Arrow.Size */ : 0;
|
|
9867
9884
|
let width = size.right - size.left, height = (_a = knownHeight.get(tView)) !== null && _a !== void 0 ? _a : size.bottom - size.top;
|
|
9868
9885
|
let offset = tView.offset || noOffset, ltr = this.view.textDirection == exports.Direction.LTR;
|
|
9869
|
-
let left = size.width > space.right - space.left
|
|
9870
|
-
|
|
9871
|
-
|
|
9886
|
+
let left = size.width > space.right - space.left
|
|
9887
|
+
? (ltr ? space.left : space.right - size.width)
|
|
9888
|
+
: ltr ? Math.max(space.left, Math.min(pos.left - (arrow ? 14 /* Arrow.Offset */ : 0) + offset.x, space.right - width))
|
|
9889
|
+
: Math.min(Math.max(space.left, pos.left - width + (arrow ? 14 /* Arrow.Offset */ : 0) - offset.x), space.right - width);
|
|
9872
9890
|
let above = this.above[i];
|
|
9873
9891
|
if (!tooltip.strictSide && (above
|
|
9874
9892
|
? pos.top - (size.bottom - size.top) - offset.y < space.top
|
package/dist/index.d.cts
CHANGED
|
@@ -1931,7 +1931,11 @@ interface TooltipView {
|
|
|
1931
1931
|
Facet to which an extension can add a value to show a tooltip.
|
|
1932
1932
|
*/
|
|
1933
1933
|
declare const showTooltip: Facet<Tooltip | null, readonly (Tooltip | null)[]>;
|
|
1934
|
-
|
|
1934
|
+
/**
|
|
1935
|
+
The type of function that can be used as a [hover tooltip
|
|
1936
|
+
source](https://codemirror.net/6/docs/ref/#view.hoverTooltip^source).
|
|
1937
|
+
*/
|
|
1938
|
+
type HoverTooltipSource = (view: EditorView, pos: number, side: -1 | 1) => Tooltip | readonly Tooltip[] | null | Promise<Tooltip | readonly Tooltip[] | null>;
|
|
1935
1939
|
/**
|
|
1936
1940
|
Set up a hover tooltip, which shows up when the pointer hovers
|
|
1937
1941
|
over ranges of text. The callback is called when the mouse hovers
|
|
@@ -1945,7 +1949,7 @@ Note that all hover tooltips are hosted within a single tooltip
|
|
|
1945
1949
|
container element. This allows multiple tooltips over the same
|
|
1946
1950
|
range to be "merged" together without overlapping.
|
|
1947
1951
|
*/
|
|
1948
|
-
declare function hoverTooltip(source:
|
|
1952
|
+
declare function hoverTooltip(source: HoverTooltipSource, options?: {
|
|
1949
1953
|
/**
|
|
1950
1954
|
Controls whether a transaction hides the tooltip. The default
|
|
1951
1955
|
is to not hide.
|
|
@@ -2180,4 +2184,4 @@ trailing whitespace.
|
|
|
2180
2184
|
*/
|
|
2181
2185
|
declare function highlightTrailingWhitespace(): Extension;
|
|
2182
2186
|
|
|
2183
|
-
export { BidiSpan, BlockInfo, BlockType, type Command, type DOMEventHandlers, type DOMEventMap, Decoration, type DecorationSet, Direction, EditorView, type EditorViewConfig, GutterMarker, type KeyBinding, type LayerMarker, MatchDecorator, type MouseSelectionStyle, type Panel, type PanelConstructor, type PluginSpec, type PluginValue, type Rect, RectangleMarker, type Tooltip, type TooltipView, ViewPlugin, ViewUpdate, WidgetType, closeHoverTooltips, crosshairCursor, drawSelection, dropCursor, getDrawSelectionConfig, getPanel, getTooltip, gutter, gutterLineClass, gutters, hasHoverTooltips, highlightActiveLine, highlightActiveLineGutter, highlightSpecialChars, highlightTrailingWhitespace, highlightWhitespace, hoverTooltip, keymap, layer, lineNumberMarkers, lineNumbers, logException, panels, placeholder, rectangularSelection, repositionTooltips, runScopeHandlers, scrollPastEnd, showPanel, showTooltip, tooltips };
|
|
2187
|
+
export { BidiSpan, BlockInfo, BlockType, type Command, type DOMEventHandlers, type DOMEventMap, Decoration, type DecorationSet, Direction, EditorView, type EditorViewConfig, GutterMarker, type HoverTooltipSource, type KeyBinding, type LayerMarker, MatchDecorator, type MouseSelectionStyle, type Panel, type PanelConstructor, type PluginSpec, type PluginValue, type Rect, RectangleMarker, type Tooltip, type TooltipView, ViewPlugin, ViewUpdate, WidgetType, closeHoverTooltips, crosshairCursor, drawSelection, dropCursor, getDrawSelectionConfig, getPanel, getTooltip, gutter, gutterLineClass, gutters, hasHoverTooltips, highlightActiveLine, highlightActiveLineGutter, highlightSpecialChars, highlightTrailingWhitespace, highlightWhitespace, hoverTooltip, keymap, layer, lineNumberMarkers, lineNumbers, logException, panels, placeholder, rectangularSelection, repositionTooltips, runScopeHandlers, scrollPastEnd, showPanel, showTooltip, tooltips };
|
package/dist/index.d.ts
CHANGED
|
@@ -1931,7 +1931,11 @@ interface TooltipView {
|
|
|
1931
1931
|
Facet to which an extension can add a value to show a tooltip.
|
|
1932
1932
|
*/
|
|
1933
1933
|
declare const showTooltip: Facet<Tooltip | null, readonly (Tooltip | null)[]>;
|
|
1934
|
-
|
|
1934
|
+
/**
|
|
1935
|
+
The type of function that can be used as a [hover tooltip
|
|
1936
|
+
source](https://codemirror.net/6/docs/ref/#view.hoverTooltip^source).
|
|
1937
|
+
*/
|
|
1938
|
+
type HoverTooltipSource = (view: EditorView, pos: number, side: -1 | 1) => Tooltip | readonly Tooltip[] | null | Promise<Tooltip | readonly Tooltip[] | null>;
|
|
1935
1939
|
/**
|
|
1936
1940
|
Set up a hover tooltip, which shows up when the pointer hovers
|
|
1937
1941
|
over ranges of text. The callback is called when the mouse hovers
|
|
@@ -1945,7 +1949,7 @@ Note that all hover tooltips are hosted within a single tooltip
|
|
|
1945
1949
|
container element. This allows multiple tooltips over the same
|
|
1946
1950
|
range to be "merged" together without overlapping.
|
|
1947
1951
|
*/
|
|
1948
|
-
declare function hoverTooltip(source:
|
|
1952
|
+
declare function hoverTooltip(source: HoverTooltipSource, options?: {
|
|
1949
1953
|
/**
|
|
1950
1954
|
Controls whether a transaction hides the tooltip. The default
|
|
1951
1955
|
is to not hide.
|
|
@@ -2180,4 +2184,4 @@ trailing whitespace.
|
|
|
2180
2184
|
*/
|
|
2181
2185
|
declare function highlightTrailingWhitespace(): Extension;
|
|
2182
2186
|
|
|
2183
|
-
export { BidiSpan, BlockInfo, BlockType, type Command, type DOMEventHandlers, type DOMEventMap, Decoration, type DecorationSet, Direction, EditorView, type EditorViewConfig, GutterMarker, type KeyBinding, type LayerMarker, MatchDecorator, type MouseSelectionStyle, type Panel, type PanelConstructor, type PluginSpec, type PluginValue, type Rect, RectangleMarker, type Tooltip, type TooltipView, ViewPlugin, ViewUpdate, WidgetType, closeHoverTooltips, crosshairCursor, drawSelection, dropCursor, getDrawSelectionConfig, getPanel, getTooltip, gutter, gutterLineClass, gutters, hasHoverTooltips, highlightActiveLine, highlightActiveLineGutter, highlightSpecialChars, highlightTrailingWhitespace, highlightWhitespace, hoverTooltip, keymap, layer, lineNumberMarkers, lineNumbers, logException, panels, placeholder, rectangularSelection, repositionTooltips, runScopeHandlers, scrollPastEnd, showPanel, showTooltip, tooltips };
|
|
2187
|
+
export { BidiSpan, BlockInfo, BlockType, type Command, type DOMEventHandlers, type DOMEventMap, Decoration, type DecorationSet, Direction, EditorView, type EditorViewConfig, GutterMarker, type HoverTooltipSource, type KeyBinding, type LayerMarker, MatchDecorator, type MouseSelectionStyle, type Panel, type PanelConstructor, type PluginSpec, type PluginValue, type Rect, RectangleMarker, type Tooltip, type TooltipView, ViewPlugin, ViewUpdate, WidgetType, closeHoverTooltips, crosshairCursor, drawSelection, dropCursor, getDrawSelectionConfig, getPanel, getTooltip, gutter, gutterLineClass, gutters, hasHoverTooltips, highlightActiveLine, highlightActiveLineGutter, highlightSpecialChars, highlightTrailingWhitespace, highlightWhitespace, hoverTooltip, keymap, layer, lineNumberMarkers, lineNumbers, logException, panels, placeholder, rectangularSelection, repositionTooltips, runScopeHandlers, scrollPastEnd, showPanel, showTooltip, tooltips };
|
package/dist/index.js
CHANGED
|
@@ -4248,8 +4248,7 @@ function rangeForClick(view, pos, bias, type) {
|
|
|
4248
4248
|
return EditorSelection.range(from, to);
|
|
4249
4249
|
}
|
|
4250
4250
|
}
|
|
4251
|
-
let
|
|
4252
|
-
let inside = (x, y, rect) => insideY(y, rect) && x >= rect.left && x <= rect.right;
|
|
4251
|
+
let inside = (x, y, rect) => y >= rect.top && y <= rect.bottom && x >= rect.left && x <= rect.right;
|
|
4253
4252
|
// Try to determine, for the given coordinates, associated with the
|
|
4254
4253
|
// given position, whether they are related to the element before or
|
|
4255
4254
|
// the element after the position.
|
|
@@ -4271,8 +4270,8 @@ function findPositionSide(view, pos, x, y) {
|
|
|
4271
4270
|
if (after && inside(x, y, after))
|
|
4272
4271
|
return 1;
|
|
4273
4272
|
// This is probably a line wrap point. Pick before if the point is
|
|
4274
|
-
//
|
|
4275
|
-
return before &&
|
|
4273
|
+
// above its bottom.
|
|
4274
|
+
return before && before.bottom >= y ? -1 : 1;
|
|
4276
4275
|
}
|
|
4277
4276
|
function queryPos(view, event) {
|
|
4278
4277
|
let pos = view.posAtCoords({ x: event.clientX, y: event.clientY }, false);
|
|
@@ -4602,6 +4601,9 @@ function firefoxCopyCutHack(doc) {
|
|
|
4602
4601
|
}
|
|
4603
4602
|
|
|
4604
4603
|
const wrappingWhiteSpace = ["pre-wrap", "normal", "pre-line", "break-spaces"];
|
|
4604
|
+
// Used to track, during updateHeight, if any actual heights changed
|
|
4605
|
+
let heightChangeFlag = false;
|
|
4606
|
+
function clearHeightChangeFlag() { heightChangeFlag = false; }
|
|
4605
4607
|
class HeightOracle {
|
|
4606
4608
|
constructor(lineWrapping) {
|
|
4607
4609
|
this.lineWrapping = lineWrapping;
|
|
@@ -4611,8 +4613,6 @@ class HeightOracle {
|
|
|
4611
4613
|
this.charWidth = 7;
|
|
4612
4614
|
this.textHeight = 14; // The height of the actual font (font-size)
|
|
4613
4615
|
this.lineLength = 30;
|
|
4614
|
-
// Used to track, during updateHeight, if any actual heights changed
|
|
4615
|
-
this.heightChanged = false;
|
|
4616
4616
|
}
|
|
4617
4617
|
heightForGap(from, to) {
|
|
4618
4618
|
let lines = this.doc.lineAt(to).number - this.doc.lineAt(from).number + 1;
|
|
@@ -4770,10 +4770,10 @@ class HeightMap {
|
|
|
4770
4770
|
}
|
|
4771
4771
|
get outdated() { return (this.flags & 2 /* Flag.Outdated */) > 0; }
|
|
4772
4772
|
set outdated(value) { this.flags = (value ? 2 /* Flag.Outdated */ : 0) | (this.flags & ~2 /* Flag.Outdated */); }
|
|
4773
|
-
setHeight(
|
|
4773
|
+
setHeight(height) {
|
|
4774
4774
|
if (this.height != height) {
|
|
4775
4775
|
if (Math.abs(this.height - height) > Epsilon)
|
|
4776
|
-
|
|
4776
|
+
heightChangeFlag = true;
|
|
4777
4777
|
this.height = height;
|
|
4778
4778
|
}
|
|
4779
4779
|
}
|
|
@@ -4804,7 +4804,7 @@ class HeightMap {
|
|
|
4804
4804
|
fromB += start.from - fromA;
|
|
4805
4805
|
fromA = start.from;
|
|
4806
4806
|
let nodes = NodeBuilder.build(oracle.setDoc(doc), decorations, fromB, toB);
|
|
4807
|
-
me = me.replace(fromA, toA, nodes);
|
|
4807
|
+
me = replace(me, me.replace(fromA, toA, nodes));
|
|
4808
4808
|
}
|
|
4809
4809
|
return me.updateHeight(oracle, 0);
|
|
4810
4810
|
}
|
|
@@ -4864,6 +4864,13 @@ class HeightMap {
|
|
|
4864
4864
|
return new HeightMapBranch(HeightMap.of(nodes.slice(0, i)), brk, HeightMap.of(nodes.slice(j)));
|
|
4865
4865
|
}
|
|
4866
4866
|
}
|
|
4867
|
+
function replace(old, val) {
|
|
4868
|
+
if (old == val)
|
|
4869
|
+
return old;
|
|
4870
|
+
if (old.constructor != val.constructor)
|
|
4871
|
+
heightChangeFlag = true;
|
|
4872
|
+
return val;
|
|
4873
|
+
}
|
|
4867
4874
|
HeightMap.prototype.size = 1;
|
|
4868
4875
|
class HeightMapBlock extends HeightMap {
|
|
4869
4876
|
constructor(length, height, deco) {
|
|
@@ -4882,7 +4889,7 @@ class HeightMapBlock extends HeightMap {
|
|
|
4882
4889
|
}
|
|
4883
4890
|
updateHeight(oracle, offset = 0, _force = false, measured) {
|
|
4884
4891
|
if (measured && measured.from <= offset && measured.more)
|
|
4885
|
-
this.setHeight(
|
|
4892
|
+
this.setHeight(measured.heights[measured.index++]);
|
|
4886
4893
|
this.outdated = false;
|
|
4887
4894
|
return this;
|
|
4888
4895
|
}
|
|
@@ -4916,9 +4923,9 @@ class HeightMapText extends HeightMapBlock {
|
|
|
4916
4923
|
}
|
|
4917
4924
|
updateHeight(oracle, offset = 0, force = false, measured) {
|
|
4918
4925
|
if (measured && measured.from <= offset && measured.more)
|
|
4919
|
-
this.setHeight(
|
|
4926
|
+
this.setHeight(measured.heights[measured.index++]);
|
|
4920
4927
|
else if (force || this.outdated)
|
|
4921
|
-
this.setHeight(
|
|
4928
|
+
this.setHeight(Math.max(this.widgetHeight, oracle.heightForLine(this.length - this.collapsed)) +
|
|
4922
4929
|
this.breaks * oracle.lineHeight);
|
|
4923
4930
|
this.outdated = false;
|
|
4924
4931
|
return this;
|
|
@@ -5041,11 +5048,11 @@ class HeightMapGap extends HeightMap {
|
|
|
5041
5048
|
let result = HeightMap.of(nodes);
|
|
5042
5049
|
if (singleHeight < 0 || Math.abs(result.height - this.height) >= Epsilon ||
|
|
5043
5050
|
Math.abs(singleHeight - this.heightMetrics(oracle, offset).perLine) >= Epsilon)
|
|
5044
|
-
|
|
5045
|
-
return result;
|
|
5051
|
+
heightChangeFlag = true;
|
|
5052
|
+
return replace(this, result);
|
|
5046
5053
|
}
|
|
5047
5054
|
else if (force || this.outdated) {
|
|
5048
|
-
this.setHeight(oracle
|
|
5055
|
+
this.setHeight(oracle.heightForGap(offset, offset + this.length));
|
|
5049
5056
|
this.outdated = false;
|
|
5050
5057
|
}
|
|
5051
5058
|
return this;
|
|
@@ -5143,9 +5150,9 @@ class HeightMapBranch extends HeightMap {
|
|
|
5143
5150
|
balanced(left, right) {
|
|
5144
5151
|
if (left.size > 2 * right.size || right.size > 2 * left.size)
|
|
5145
5152
|
return HeightMap.of(this.break ? [left, null, right] : [left, right]);
|
|
5146
|
-
this.left = left;
|
|
5147
|
-
this.right = right;
|
|
5148
|
-
this.
|
|
5153
|
+
this.left = replace(this.left, left);
|
|
5154
|
+
this.right = replace(this.right, right);
|
|
5155
|
+
this.setHeight(left.height + right.height);
|
|
5149
5156
|
this.outdated = left.outdated || right.outdated;
|
|
5150
5157
|
this.size = left.size + right.size;
|
|
5151
5158
|
this.length = left.length + this.break + right.length;
|
|
@@ -5484,8 +5491,9 @@ class ViewState {
|
|
|
5484
5491
|
let heightChanges = ChangedRange.extendWithRanges(contentChanges, heightRelevantDecoChanges(prevDeco, this.stateDeco, update ? update.changes : ChangeSet.empty(this.state.doc.length)));
|
|
5485
5492
|
let prevHeight = this.heightMap.height;
|
|
5486
5493
|
let scrollAnchor = this.scrolledToBottom ? null : this.scrollAnchorAt(this.scrollTop);
|
|
5494
|
+
clearHeightChangeFlag();
|
|
5487
5495
|
this.heightMap = this.heightMap.applyChanges(this.stateDeco, update.startState.doc, this.heightOracle.setDoc(this.state.doc), heightChanges);
|
|
5488
|
-
if (this.heightMap.height != prevHeight)
|
|
5496
|
+
if (this.heightMap.height != prevHeight || heightChangeFlag)
|
|
5489
5497
|
update.flags |= 2 /* UpdateFlag.Height */;
|
|
5490
5498
|
if (scrollAnchor) {
|
|
5491
5499
|
this.scrollAnchorPos = update.changes.mapPos(scrollAnchor.from, -1);
|
|
@@ -5589,12 +5597,12 @@ class ViewState {
|
|
|
5589
5597
|
bias = Math.max(dTop, dBottom);
|
|
5590
5598
|
else if (dTop < 0 && dBottom < 0)
|
|
5591
5599
|
bias = Math.min(dTop, dBottom);
|
|
5592
|
-
|
|
5600
|
+
clearHeightChangeFlag();
|
|
5593
5601
|
for (let vp of this.viewports) {
|
|
5594
5602
|
let heights = vp.from == this.viewport.from ? lineHeights : view.docView.measureVisibleLineHeights(vp);
|
|
5595
5603
|
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));
|
|
5596
5604
|
}
|
|
5597
|
-
if (
|
|
5605
|
+
if (heightChangeFlag)
|
|
5598
5606
|
result |= 2 /* UpdateFlag.Height */;
|
|
5599
5607
|
}
|
|
5600
5608
|
let viewportChange = !this.viewportIsAppropriate(this.viewport, bias) ||
|
|
@@ -6714,7 +6722,7 @@ class DOMObserver {
|
|
|
6714
6722
|
}, 50);
|
|
6715
6723
|
}
|
|
6716
6724
|
onPrint(event) {
|
|
6717
|
-
if (event.type == "change" && !event.matches)
|
|
6725
|
+
if ((event.type == "change" || !event.type) && !event.matches)
|
|
6718
6726
|
return;
|
|
6719
6727
|
this.view.viewState.printing = true;
|
|
6720
6728
|
this.view.measure();
|
|
@@ -6997,8 +7005,12 @@ class DOMObserver {
|
|
|
6997
7005
|
}
|
|
6998
7006
|
addWindowListeners(win) {
|
|
6999
7007
|
win.addEventListener("resize", this.onResize);
|
|
7000
|
-
if (this.printQuery)
|
|
7001
|
-
this.printQuery.addEventListener
|
|
7008
|
+
if (this.printQuery) {
|
|
7009
|
+
if (this.printQuery.addEventListener)
|
|
7010
|
+
this.printQuery.addEventListener("change", this.onPrint);
|
|
7011
|
+
else
|
|
7012
|
+
this.printQuery.addListener(this.onPrint);
|
|
7013
|
+
}
|
|
7002
7014
|
else
|
|
7003
7015
|
win.addEventListener("beforeprint", this.onPrint);
|
|
7004
7016
|
win.addEventListener("scroll", this.onScroll);
|
|
@@ -7007,8 +7019,12 @@ class DOMObserver {
|
|
|
7007
7019
|
removeWindowListeners(win) {
|
|
7008
7020
|
win.removeEventListener("scroll", this.onScroll);
|
|
7009
7021
|
win.removeEventListener("resize", this.onResize);
|
|
7010
|
-
if (this.printQuery)
|
|
7011
|
-
this.printQuery.removeEventListener
|
|
7022
|
+
if (this.printQuery) {
|
|
7023
|
+
if (this.printQuery.removeEventListener)
|
|
7024
|
+
this.printQuery.removeEventListener("change", this.onPrint);
|
|
7025
|
+
else
|
|
7026
|
+
this.printQuery.removeListener(this.onPrint);
|
|
7027
|
+
}
|
|
7012
7028
|
else
|
|
7013
7029
|
win.removeEventListener("beforeprint", this.onPrint);
|
|
7014
7030
|
win.document.removeEventListener("selectionchange", this.onSelectionChange);
|
|
@@ -7118,7 +7134,8 @@ class EditContextManager {
|
|
|
7118
7134
|
if (change.from == change.to && !change.insert.length)
|
|
7119
7135
|
return;
|
|
7120
7136
|
this.pendingContextChange = change;
|
|
7121
|
-
|
|
7137
|
+
if (!view.state.readOnly)
|
|
7138
|
+
applyDOMChangeInner(view, change, EditorSelection.single(this.toEditorPos(e.selectionStart), this.toEditorPos(e.selectionEnd)));
|
|
7122
7139
|
// If the transaction didn't flush our change, revert it so
|
|
7123
7140
|
// that the context is in sync with the editor state again.
|
|
7124
7141
|
if (this.pendingContextChange) {
|
|
@@ -9861,9 +9878,10 @@ const tooltipPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
|
9861
9878
|
let arrowHeight = arrow ? 7 /* Arrow.Size */ : 0;
|
|
9862
9879
|
let width = size.right - size.left, height = (_a = knownHeight.get(tView)) !== null && _a !== void 0 ? _a : size.bottom - size.top;
|
|
9863
9880
|
let offset = tView.offset || noOffset, ltr = this.view.textDirection == Direction.LTR;
|
|
9864
|
-
let left = size.width > space.right - space.left
|
|
9865
|
-
|
|
9866
|
-
|
|
9881
|
+
let left = size.width > space.right - space.left
|
|
9882
|
+
? (ltr ? space.left : space.right - size.width)
|
|
9883
|
+
: ltr ? Math.max(space.left, Math.min(pos.left - (arrow ? 14 /* Arrow.Offset */ : 0) + offset.x, space.right - width))
|
|
9884
|
+
: Math.min(Math.max(space.left, pos.left - width + (arrow ? 14 /* Arrow.Offset */ : 0) - offset.x), space.right - width);
|
|
9867
9885
|
let above = this.above[i];
|
|
9868
9886
|
if (!tooltip.strictSide && (above
|
|
9869
9887
|
? pos.top - (size.bottom - size.top) - offset.y < space.top
|