@codemirror/view 6.28.5 → 6.29.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 +18 -0
- package/dist/index.cjs +15 -11
- package/dist/index.d.cts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +15 -11
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## 6.29.0 (2024-07-25)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Fix an issue that caused typing into an editor marked read-only to cause document changes when using `EditContext`.
|
|
6
|
+
|
|
7
|
+
Associate a cursor created by clicking above the end of the text on a wrap point with the line before it.
|
|
8
|
+
|
|
9
|
+
### New features
|
|
10
|
+
|
|
11
|
+
The package now exports the type of hover tooltip sources as `HoverTooltipSource`.
|
|
12
|
+
|
|
13
|
+
## 6.28.6 (2024-07-19)
|
|
14
|
+
|
|
15
|
+
### Bug fixes
|
|
16
|
+
|
|
17
|
+
Fix an issue where the editor got confused about the position of inserted text when using Chrome's `EditContext` and canceling transactions for typed text.
|
|
18
|
+
|
|
1
19
|
## 6.28.5 (2024-07-17)
|
|
2
20
|
|
|
3
21
|
### 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);
|
|
@@ -7123,11 +7122,14 @@ class EditContextManager {
|
|
|
7123
7122
|
if (change.from == change.to && !change.insert.length)
|
|
7124
7123
|
return;
|
|
7125
7124
|
this.pendingContextChange = change;
|
|
7126
|
-
|
|
7125
|
+
if (!view.state.readOnly)
|
|
7126
|
+
applyDOMChangeInner(view, change, state.EditorSelection.single(this.toEditorPos(e.selectionStart), this.toEditorPos(e.selectionEnd)));
|
|
7127
7127
|
// If the transaction didn't flush our change, revert it so
|
|
7128
7128
|
// that the context is in sync with the editor state again.
|
|
7129
|
-
if (this.pendingContextChange)
|
|
7129
|
+
if (this.pendingContextChange) {
|
|
7130
7130
|
this.revertPending(view.state);
|
|
7131
|
+
this.setSelection(view.state);
|
|
7132
|
+
}
|
|
7131
7133
|
};
|
|
7132
7134
|
this.handlers.characterboundsupdate = e => {
|
|
7133
7135
|
let rects = [], prev = null;
|
|
@@ -7209,13 +7211,14 @@ class EditContextManager {
|
|
|
7209
7211
|
return !abort;
|
|
7210
7212
|
}
|
|
7211
7213
|
update(update) {
|
|
7214
|
+
let reverted = this.pendingContextChange;
|
|
7212
7215
|
if (!this.applyEdits(update) || !this.rangeIsValid(update.state)) {
|
|
7213
7216
|
this.pendingContextChange = null;
|
|
7214
7217
|
this.resetRange(update.state);
|
|
7215
7218
|
this.editContext.updateText(0, this.editContext.text.length, update.state.doc.sliceString(this.from, this.to));
|
|
7216
7219
|
this.setSelection(update.state);
|
|
7217
7220
|
}
|
|
7218
|
-
else if (update.docChanged || update.selectionSet) {
|
|
7221
|
+
else if (update.docChanged || update.selectionSet || reverted) {
|
|
7219
7222
|
this.setSelection(update.state);
|
|
7220
7223
|
}
|
|
7221
7224
|
if (update.geometryChanged || update.docChanged || update.selectionSet)
|
|
@@ -7229,7 +7232,7 @@ class EditContextManager {
|
|
|
7229
7232
|
revertPending(state) {
|
|
7230
7233
|
let pending = this.pendingContextChange;
|
|
7231
7234
|
this.pendingContextChange = null;
|
|
7232
|
-
this.editContext.updateText(this.toContextPos(pending.from), this.toContextPos(pending.
|
|
7235
|
+
this.editContext.updateText(this.toContextPos(pending.from), this.toContextPos(pending.from + pending.insert.length), state.doc.sliceString(pending.from, pending.to));
|
|
7233
7236
|
}
|
|
7234
7237
|
setSelection(state) {
|
|
7235
7238
|
let { main } = state.selection;
|
|
@@ -9863,9 +9866,10 @@ const tooltipPlugin = ViewPlugin.fromClass(class {
|
|
|
9863
9866
|
let arrowHeight = arrow ? 7 /* Arrow.Size */ : 0;
|
|
9864
9867
|
let width = size.right - size.left, height = (_a = knownHeight.get(tView)) !== null && _a !== void 0 ? _a : size.bottom - size.top;
|
|
9865
9868
|
let offset = tView.offset || noOffset, ltr = this.view.textDirection == exports.Direction.LTR;
|
|
9866
|
-
let left = size.width > space.right - space.left
|
|
9867
|
-
|
|
9868
|
-
|
|
9869
|
+
let left = size.width > space.right - space.left
|
|
9870
|
+
? (ltr ? space.left : space.right - size.width)
|
|
9871
|
+
: ltr ? Math.max(space.left, Math.min(pos.left - (arrow ? 14 /* Arrow.Offset */ : 0) + offset.x, space.right - width))
|
|
9872
|
+
: Math.min(Math.max(space.left, pos.left - width + (arrow ? 14 /* Arrow.Offset */ : 0) - offset.x), space.right - width);
|
|
9869
9873
|
let above = this.above[i];
|
|
9870
9874
|
if (!tooltip.strictSide && (above
|
|
9871
9875
|
? 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);
|
|
@@ -7118,11 +7117,14 @@ class EditContextManager {
|
|
|
7118
7117
|
if (change.from == change.to && !change.insert.length)
|
|
7119
7118
|
return;
|
|
7120
7119
|
this.pendingContextChange = change;
|
|
7121
|
-
|
|
7120
|
+
if (!view.state.readOnly)
|
|
7121
|
+
applyDOMChangeInner(view, change, EditorSelection.single(this.toEditorPos(e.selectionStart), this.toEditorPos(e.selectionEnd)));
|
|
7122
7122
|
// If the transaction didn't flush our change, revert it so
|
|
7123
7123
|
// that the context is in sync with the editor state again.
|
|
7124
|
-
if (this.pendingContextChange)
|
|
7124
|
+
if (this.pendingContextChange) {
|
|
7125
7125
|
this.revertPending(view.state);
|
|
7126
|
+
this.setSelection(view.state);
|
|
7127
|
+
}
|
|
7126
7128
|
};
|
|
7127
7129
|
this.handlers.characterboundsupdate = e => {
|
|
7128
7130
|
let rects = [], prev = null;
|
|
@@ -7204,13 +7206,14 @@ class EditContextManager {
|
|
|
7204
7206
|
return !abort;
|
|
7205
7207
|
}
|
|
7206
7208
|
update(update) {
|
|
7209
|
+
let reverted = this.pendingContextChange;
|
|
7207
7210
|
if (!this.applyEdits(update) || !this.rangeIsValid(update.state)) {
|
|
7208
7211
|
this.pendingContextChange = null;
|
|
7209
7212
|
this.resetRange(update.state);
|
|
7210
7213
|
this.editContext.updateText(0, this.editContext.text.length, update.state.doc.sliceString(this.from, this.to));
|
|
7211
7214
|
this.setSelection(update.state);
|
|
7212
7215
|
}
|
|
7213
|
-
else if (update.docChanged || update.selectionSet) {
|
|
7216
|
+
else if (update.docChanged || update.selectionSet || reverted) {
|
|
7214
7217
|
this.setSelection(update.state);
|
|
7215
7218
|
}
|
|
7216
7219
|
if (update.geometryChanged || update.docChanged || update.selectionSet)
|
|
@@ -7224,7 +7227,7 @@ class EditContextManager {
|
|
|
7224
7227
|
revertPending(state) {
|
|
7225
7228
|
let pending = this.pendingContextChange;
|
|
7226
7229
|
this.pendingContextChange = null;
|
|
7227
|
-
this.editContext.updateText(this.toContextPos(pending.from), this.toContextPos(pending.
|
|
7230
|
+
this.editContext.updateText(this.toContextPos(pending.from), this.toContextPos(pending.from + pending.insert.length), state.doc.sliceString(pending.from, pending.to));
|
|
7228
7231
|
}
|
|
7229
7232
|
setSelection(state) {
|
|
7230
7233
|
let { main } = state.selection;
|
|
@@ -9858,9 +9861,10 @@ const tooltipPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
|
|
|
9858
9861
|
let arrowHeight = arrow ? 7 /* Arrow.Size */ : 0;
|
|
9859
9862
|
let width = size.right - size.left, height = (_a = knownHeight.get(tView)) !== null && _a !== void 0 ? _a : size.bottom - size.top;
|
|
9860
9863
|
let offset = tView.offset || noOffset, ltr = this.view.textDirection == Direction.LTR;
|
|
9861
|
-
let left = size.width > space.right - space.left
|
|
9862
|
-
|
|
9863
|
-
|
|
9864
|
+
let left = size.width > space.right - space.left
|
|
9865
|
+
? (ltr ? space.left : space.right - size.width)
|
|
9866
|
+
: ltr ? Math.max(space.left, Math.min(pos.left - (arrow ? 14 /* Arrow.Offset */ : 0) + offset.x, space.right - width))
|
|
9867
|
+
: Math.min(Math.max(space.left, pos.left - width + (arrow ? 14 /* Arrow.Offset */ : 0) - offset.x), space.right - width);
|
|
9864
9868
|
let above = this.above[i];
|
|
9865
9869
|
if (!tooltip.strictSide && (above
|
|
9866
9870
|
? pos.top - (size.bottom - size.top) - offset.y < space.top
|