@codemirror/view 6.13.2 → 6.14.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 +12 -0
- package/dist/index.cjs +8 -6
- package/dist/index.d.cts +9 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.js +8 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## 6.14.0 (2023-06-23)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
When dragging text inside the editor, look at the state of Ctrl (or Alt on macOS) at the time of the drop, not the start of drag, to determine whether to move or copy the text.
|
|
6
|
+
|
|
7
|
+
Fix an issue where having a bunch of padding on lines could cause vertical cursor motion and `posAtCoords` to jump over lines.
|
|
8
|
+
|
|
9
|
+
### New features
|
|
10
|
+
|
|
11
|
+
Block widget decorations can now be given an `inlineOrder` option to make them appear in the same ordering as surrounding inline widgets.
|
|
12
|
+
|
|
1
13
|
## 6.13.2 (2023-06-13)
|
|
2
14
|
|
|
3
15
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -1327,7 +1327,9 @@ class Decoration extends state.RangeValue {
|
|
|
1327
1327
|
*/
|
|
1328
1328
|
static widget(spec) {
|
|
1329
1329
|
let side = Math.max(-10000, Math.min(10000, spec.side || 0)), block = !!spec.block;
|
|
1330
|
-
side += block
|
|
1330
|
+
side += (block && !spec.inlineOrder)
|
|
1331
|
+
? (side > 0 ? 300000000 /* BlockAfter */ : -400000000 /* BlockBefore */)
|
|
1332
|
+
: (side > 0 ? 100000000 /* InlineAfter */ : -100000000 /* InlineBefore */);
|
|
1331
1333
|
return new PointDecoration(spec, side, side, block, spec.widget || null, false);
|
|
1332
1334
|
}
|
|
1333
1335
|
/**
|
|
@@ -3272,7 +3274,7 @@ function posAtCoords(view, coords, precise, bias = -1) {
|
|
|
3272
3274
|
if (yOffset > docHeight)
|
|
3273
3275
|
return view.state.doc.length;
|
|
3274
3276
|
// Scan for a text block near the queried y position
|
|
3275
|
-
for (let halfLine = view.
|
|
3277
|
+
for (let halfLine = view.viewState.heightOracle.textHeight / 2, bounced = false;;) {
|
|
3276
3278
|
block = view.elementAtHeight(yOffset);
|
|
3277
3279
|
if (block.type == exports.BlockType.Text)
|
|
3278
3280
|
break;
|
|
@@ -3352,7 +3354,8 @@ function posAtCoords(view, coords, precise, bias = -1) {
|
|
|
3352
3354
|
function posAtCoordsImprecise(view, contentRect, block, x, y) {
|
|
3353
3355
|
let into = Math.round((x - contentRect.left) * view.defaultCharacterWidth);
|
|
3354
3356
|
if (view.lineWrapping && block.height > view.defaultLineHeight * 1.5) {
|
|
3355
|
-
let
|
|
3357
|
+
let textHeight = view.viewState.heightOracle.textHeight;
|
|
3358
|
+
let line = Math.floor((y - block.top - (view.defaultLineHeight - textHeight) * 0.5) / textHeight);
|
|
3356
3359
|
into += line * view.viewState.heightOracle.lineLength;
|
|
3357
3360
|
}
|
|
3358
3361
|
let content = view.state.sliceDoc(block.from, block.to);
|
|
@@ -3463,7 +3466,7 @@ function moveVertically(view, start, forward, distance) {
|
|
|
3463
3466
|
startY = (dir < 0 ? line.top : line.bottom) + docTop;
|
|
3464
3467
|
}
|
|
3465
3468
|
let resolvedGoal = rect.left + goal;
|
|
3466
|
-
let dist = distance !== null && distance !== void 0 ? distance : (view.
|
|
3469
|
+
let dist = distance !== null && distance !== void 0 ? distance : (view.viewState.heightOracle.textHeight >> 1);
|
|
3467
3470
|
for (let extra = 0;; extra += 10) {
|
|
3468
3471
|
let curY = startY + (dist + extra) * dir;
|
|
3469
3472
|
let pos = posAtCoords(view, { x: resolvedGoal, y: curY }, false, dir);
|
|
@@ -3746,7 +3749,6 @@ class MouseSelection {
|
|
|
3746
3749
|
doc.addEventListener("mouseup", this.up = this.up.bind(this));
|
|
3747
3750
|
this.extend = startEvent.shiftKey;
|
|
3748
3751
|
this.multiple = view.state.facet(state.EditorState.allowMultipleSelections) && addsSelectionRange(view, startEvent);
|
|
3749
|
-
this.dragMove = dragMovesSelection(view, startEvent);
|
|
3750
3752
|
this.dragging = isInPrimarySelection(view, startEvent) && getClickType(startEvent) == 1 ? null : false;
|
|
3751
3753
|
}
|
|
3752
3754
|
start(event) {
|
|
@@ -4084,7 +4086,7 @@ function dropText(view, event, text, direct) {
|
|
|
4084
4086
|
let dropPos = view.posAtCoords({ x: event.clientX, y: event.clientY }, false);
|
|
4085
4087
|
event.preventDefault();
|
|
4086
4088
|
let { mouseSelection } = view.inputState;
|
|
4087
|
-
let del = direct && mouseSelection && mouseSelection.dragging &&
|
|
4089
|
+
let del = direct && mouseSelection && mouseSelection.dragging && dragMovesSelection(view, event) ?
|
|
4088
4090
|
{ from: mouseSelection.dragging.from, to: mouseSelection.dragging.to } : null;
|
|
4089
4091
|
let ins = { from: dropPos, insert: text };
|
|
4090
4092
|
let changes = view.state.changes(del ? [del, ins] : ins);
|
package/dist/index.d.cts
CHANGED
|
@@ -72,13 +72,18 @@ interface WidgetDecorationSpec {
|
|
|
72
72
|
values will determine their ordering—those with a lower value
|
|
73
73
|
come first. Defaults to 0. May not be more than 10000 or less
|
|
74
74
|
than -10000.
|
|
75
|
-
|
|
76
|
-
Block widgets are always drawn before inline widgets when side
|
|
77
|
-
is non-positive, and after them when side is positive,
|
|
78
|
-
regardless of the value of `side`.
|
|
79
75
|
*/
|
|
80
76
|
side?: number;
|
|
81
77
|
/**
|
|
78
|
+
By default, to avoid unintended mixing of block and inline
|
|
79
|
+
widgets, block widgets with a positive `side` are always drawn
|
|
80
|
+
after all inline widgets at that position, and those with a
|
|
81
|
+
non-positive side before inline widgets. Setting this option to
|
|
82
|
+
`true` for a block widget will turn this off and cause it to be
|
|
83
|
+
rendered between the inline widgets, ordered by `side`.
|
|
84
|
+
*/
|
|
85
|
+
inlineOrder?: boolean;
|
|
86
|
+
/**
|
|
82
87
|
Determines whether this is a block widgets, which will be drawn
|
|
83
88
|
between lines, or an inline widget (the default) which is drawn
|
|
84
89
|
between the surrounding text.
|
package/dist/index.d.ts
CHANGED
|
@@ -72,13 +72,18 @@ interface WidgetDecorationSpec {
|
|
|
72
72
|
values will determine their ordering—those with a lower value
|
|
73
73
|
come first. Defaults to 0. May not be more than 10000 or less
|
|
74
74
|
than -10000.
|
|
75
|
-
|
|
76
|
-
Block widgets are always drawn before inline widgets when side
|
|
77
|
-
is non-positive, and after them when side is positive,
|
|
78
|
-
regardless of the value of `side`.
|
|
79
75
|
*/
|
|
80
76
|
side?: number;
|
|
81
77
|
/**
|
|
78
|
+
By default, to avoid unintended mixing of block and inline
|
|
79
|
+
widgets, block widgets with a positive `side` are always drawn
|
|
80
|
+
after all inline widgets at that position, and those with a
|
|
81
|
+
non-positive side before inline widgets. Setting this option to
|
|
82
|
+
`true` for a block widget will turn this off and cause it to be
|
|
83
|
+
rendered between the inline widgets, ordered by `side`.
|
|
84
|
+
*/
|
|
85
|
+
inlineOrder?: boolean;
|
|
86
|
+
/**
|
|
82
87
|
Determines whether this is a block widgets, which will be drawn
|
|
83
88
|
between lines, or an inline widget (the default) which is drawn
|
|
84
89
|
between the surrounding text.
|
package/dist/index.js
CHANGED
|
@@ -1322,7 +1322,9 @@ class Decoration extends RangeValue {
|
|
|
1322
1322
|
*/
|
|
1323
1323
|
static widget(spec) {
|
|
1324
1324
|
let side = Math.max(-10000, Math.min(10000, spec.side || 0)), block = !!spec.block;
|
|
1325
|
-
side += block
|
|
1325
|
+
side += (block && !spec.inlineOrder)
|
|
1326
|
+
? (side > 0 ? 300000000 /* BlockAfter */ : -400000000 /* BlockBefore */)
|
|
1327
|
+
: (side > 0 ? 100000000 /* InlineAfter */ : -100000000 /* InlineBefore */);
|
|
1326
1328
|
return new PointDecoration(spec, side, side, block, spec.widget || null, false);
|
|
1327
1329
|
}
|
|
1328
1330
|
/**
|
|
@@ -3266,7 +3268,7 @@ function posAtCoords(view, coords, precise, bias = -1) {
|
|
|
3266
3268
|
if (yOffset > docHeight)
|
|
3267
3269
|
return view.state.doc.length;
|
|
3268
3270
|
// Scan for a text block near the queried y position
|
|
3269
|
-
for (let halfLine = view.
|
|
3271
|
+
for (let halfLine = view.viewState.heightOracle.textHeight / 2, bounced = false;;) {
|
|
3270
3272
|
block = view.elementAtHeight(yOffset);
|
|
3271
3273
|
if (block.type == BlockType.Text)
|
|
3272
3274
|
break;
|
|
@@ -3346,7 +3348,8 @@ function posAtCoords(view, coords, precise, bias = -1) {
|
|
|
3346
3348
|
function posAtCoordsImprecise(view, contentRect, block, x, y) {
|
|
3347
3349
|
let into = Math.round((x - contentRect.left) * view.defaultCharacterWidth);
|
|
3348
3350
|
if (view.lineWrapping && block.height > view.defaultLineHeight * 1.5) {
|
|
3349
|
-
let
|
|
3351
|
+
let textHeight = view.viewState.heightOracle.textHeight;
|
|
3352
|
+
let line = Math.floor((y - block.top - (view.defaultLineHeight - textHeight) * 0.5) / textHeight);
|
|
3350
3353
|
into += line * view.viewState.heightOracle.lineLength;
|
|
3351
3354
|
}
|
|
3352
3355
|
let content = view.state.sliceDoc(block.from, block.to);
|
|
@@ -3457,7 +3460,7 @@ function moveVertically(view, start, forward, distance) {
|
|
|
3457
3460
|
startY = (dir < 0 ? line.top : line.bottom) + docTop;
|
|
3458
3461
|
}
|
|
3459
3462
|
let resolvedGoal = rect.left + goal;
|
|
3460
|
-
let dist = distance !== null && distance !== void 0 ? distance : (view.
|
|
3463
|
+
let dist = distance !== null && distance !== void 0 ? distance : (view.viewState.heightOracle.textHeight >> 1);
|
|
3461
3464
|
for (let extra = 0;; extra += 10) {
|
|
3462
3465
|
let curY = startY + (dist + extra) * dir;
|
|
3463
3466
|
let pos = posAtCoords(view, { x: resolvedGoal, y: curY }, false, dir);
|
|
@@ -3740,7 +3743,6 @@ class MouseSelection {
|
|
|
3740
3743
|
doc.addEventListener("mouseup", this.up = this.up.bind(this));
|
|
3741
3744
|
this.extend = startEvent.shiftKey;
|
|
3742
3745
|
this.multiple = view.state.facet(EditorState.allowMultipleSelections) && addsSelectionRange(view, startEvent);
|
|
3743
|
-
this.dragMove = dragMovesSelection(view, startEvent);
|
|
3744
3746
|
this.dragging = isInPrimarySelection(view, startEvent) && getClickType(startEvent) == 1 ? null : false;
|
|
3745
3747
|
}
|
|
3746
3748
|
start(event) {
|
|
@@ -4078,7 +4080,7 @@ function dropText(view, event, text, direct) {
|
|
|
4078
4080
|
let dropPos = view.posAtCoords({ x: event.clientX, y: event.clientY }, false);
|
|
4079
4081
|
event.preventDefault();
|
|
4080
4082
|
let { mouseSelection } = view.inputState;
|
|
4081
|
-
let del = direct && mouseSelection && mouseSelection.dragging &&
|
|
4083
|
+
let del = direct && mouseSelection && mouseSelection.dragging && dragMovesSelection(view, event) ?
|
|
4082
4084
|
{ from: mouseSelection.dragging.from, to: mouseSelection.dragging.to } : null;
|
|
4083
4085
|
let ins = { from: dropPos, insert: text };
|
|
4084
4086
|
let changes = view.state.changes(del ? [del, ins] : ins);
|