@codemirror/view 0.20.3 → 0.20.4
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 +8 -0
- package/dist/index.cjs +25 -13
- package/dist/index.d.ts +26 -6
- package/dist/index.js +25 -13
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## 0.20.4 (2022-05-03)
|
|
2
|
+
|
|
3
|
+
### Bug fixes
|
|
4
|
+
|
|
5
|
+
Prevent Mac-style behavior of inserting a period when the user inserts two spaces.
|
|
6
|
+
|
|
7
|
+
Fix an issue where the editor would sometimes not restore the DOM selection when refocused with a selection identical to the one it held when it lost focus.
|
|
8
|
+
|
|
1
9
|
## 0.20.3 (2022-04-27)
|
|
2
10
|
|
|
3
11
|
### Bug fixes
|
package/dist/index.cjs
CHANGED
|
@@ -1157,9 +1157,6 @@ of content. You'll usually use it wrapped in a
|
|
|
1157
1157
|
@nonabstract
|
|
1158
1158
|
*/
|
|
1159
1159
|
class Decoration extends state.RangeValue {
|
|
1160
|
-
/**
|
|
1161
|
-
@internal
|
|
1162
|
-
*/
|
|
1163
1160
|
constructor(
|
|
1164
1161
|
/**
|
|
1165
1162
|
@internal
|
|
@@ -1704,7 +1701,6 @@ class NullWidget extends WidgetType {
|
|
|
1704
1701
|
updateDOM(elt) { return elt.nodeName.toLowerCase() == this.tag; }
|
|
1705
1702
|
}
|
|
1706
1703
|
|
|
1707
|
-
const none = [];
|
|
1708
1704
|
const clickAddsSelectionRange = state.Facet.define();
|
|
1709
1705
|
const dragMovesSelection$1 = state.Facet.define();
|
|
1710
1706
|
const mouseSelectionStyle = state.Facet.define();
|
|
@@ -1923,9 +1919,6 @@ View [plugins](https://codemirror.net/6/docs/ref/#view.ViewPlugin) are given ins
|
|
|
1923
1919
|
class, which describe what happened, whenever the view is updated.
|
|
1924
1920
|
*/
|
|
1925
1921
|
class ViewUpdate {
|
|
1926
|
-
/**
|
|
1927
|
-
@internal
|
|
1928
|
-
*/
|
|
1929
1922
|
constructor(
|
|
1930
1923
|
/**
|
|
1931
1924
|
The editor view that the update is associated with.
|
|
@@ -1938,7 +1931,7 @@ class ViewUpdate {
|
|
|
1938
1931
|
/**
|
|
1939
1932
|
The transactions involved in the update. May be empty.
|
|
1940
1933
|
*/
|
|
1941
|
-
transactions
|
|
1934
|
+
transactions) {
|
|
1942
1935
|
this.view = view;
|
|
1943
1936
|
this.state = state$1;
|
|
1944
1937
|
this.transactions = transactions;
|
|
@@ -1960,6 +1953,12 @@ class ViewUpdate {
|
|
|
1960
1953
|
}
|
|
1961
1954
|
}
|
|
1962
1955
|
/**
|
|
1956
|
+
@internal
|
|
1957
|
+
*/
|
|
1958
|
+
static create(view, state, transactions) {
|
|
1959
|
+
return new ViewUpdate(view, state, transactions);
|
|
1960
|
+
}
|
|
1961
|
+
/**
|
|
1963
1962
|
Tells you whether the [viewport](https://codemirror.net/6/docs/ref/#view.EditorView.viewport) or
|
|
1964
1963
|
[visible ranges](https://codemirror.net/6/docs/ref/#view.EditorView.visibleRanges) changed in this
|
|
1965
1964
|
update.
|
|
@@ -3845,11 +3844,16 @@ handlers.copy = handlers.cut = (view, event) => {
|
|
|
3845
3844
|
userEvent: "delete.cut"
|
|
3846
3845
|
});
|
|
3847
3846
|
};
|
|
3848
|
-
|
|
3847
|
+
function updateForFocusChange(view) {
|
|
3849
3848
|
setTimeout(() => {
|
|
3850
3849
|
if (view.hasFocus != view.inputState.notifiedFocused)
|
|
3851
3850
|
view.update([]);
|
|
3852
3851
|
}, 10);
|
|
3852
|
+
}
|
|
3853
|
+
handlers.focus = updateForFocusChange;
|
|
3854
|
+
handlers.blur = view => {
|
|
3855
|
+
view.observer.clearSelectionRange();
|
|
3856
|
+
updateForFocusChange(view);
|
|
3853
3857
|
};
|
|
3854
3858
|
function forceClearComposition(view, rapid) {
|
|
3855
3859
|
if (view.docView.compositionDeco.size) {
|
|
@@ -5487,6 +5491,9 @@ class DOMObserver {
|
|
|
5487
5491
|
this.selectionRange.set(anchor.node, anchor.offset, head.node, head.offset);
|
|
5488
5492
|
this.selectionChanged = false;
|
|
5489
5493
|
}
|
|
5494
|
+
clearSelectionRange() {
|
|
5495
|
+
this.selectionRange.set(null, 0, null, 0);
|
|
5496
|
+
}
|
|
5490
5497
|
listenForScroll() {
|
|
5491
5498
|
this.parentCheck = -1;
|
|
5492
5499
|
let i = 0, changed = null;
|
|
@@ -5766,6 +5773,11 @@ function applyDOMChange(view, start, end, typeOver) {
|
|
|
5766
5773
|
from: sel.from, to: sel.to,
|
|
5767
5774
|
insert: view.state.doc.slice(sel.from, change.from).append(change.insert).append(view.state.doc.slice(change.to, sel.to))
|
|
5768
5775
|
};
|
|
5776
|
+
// Detect insert-period-on-double-space Mac behavior, and transform
|
|
5777
|
+
// it into a regular space insert.
|
|
5778
|
+
else if (browser.mac && change && change.from == change.to && change.from == sel.head - 1 &&
|
|
5779
|
+
change.insert.toString() == ".")
|
|
5780
|
+
change = { from: sel.from, to: sel.to, insert: state.Text.of([" "]) };
|
|
5769
5781
|
if (change) {
|
|
5770
5782
|
let startState = view.state;
|
|
5771
5783
|
if (browser.ios && view.inputState.flushIOSKey(view))
|
|
@@ -6054,7 +6066,7 @@ class EditorView {
|
|
|
6054
6066
|
// When the phrases change, redraw the editor
|
|
6055
6067
|
if (state$1.facet(state.EditorState.phrases) != this.state.facet(state.EditorState.phrases))
|
|
6056
6068
|
return this.setState(state$1);
|
|
6057
|
-
update =
|
|
6069
|
+
update = ViewUpdate.create(this, state$1, transactions);
|
|
6058
6070
|
let scrollTarget = this.viewState.scrollTarget;
|
|
6059
6071
|
try {
|
|
6060
6072
|
this.updateState = 2 /* Updating */;
|
|
@@ -6197,7 +6209,7 @@ class EditorView {
|
|
|
6197
6209
|
return BadMeasure;
|
|
6198
6210
|
}
|
|
6199
6211
|
});
|
|
6200
|
-
let update =
|
|
6212
|
+
let update = ViewUpdate.create(this, this.state, []), redrawn = false, scrolled = false;
|
|
6201
6213
|
update.flags |= changed;
|
|
6202
6214
|
if (!updated)
|
|
6203
6215
|
updated = update;
|
|
@@ -6657,8 +6669,8 @@ EditorView.inputHandler = inputHandler;
|
|
|
6657
6669
|
/**
|
|
6658
6670
|
By default, the editor assumes all its content has the same
|
|
6659
6671
|
[text direction](https://codemirror.net/6/docs/ref/#view.Direction). Configure this with a `true`
|
|
6660
|
-
value to make it read
|
|
6661
|
-
|
|
6672
|
+
value to make it read the text direction of every (rendered)
|
|
6673
|
+
line separately.
|
|
6662
6674
|
*/
|
|
6663
6675
|
EditorView.perLineTextDirection = perLineTextDirection;
|
|
6664
6676
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -214,6 +214,25 @@ declare abstract class Decoration extends RangeValue {
|
|
|
214
214
|
your decoration.
|
|
215
215
|
*/
|
|
216
216
|
readonly spec: any;
|
|
217
|
+
protected constructor(
|
|
218
|
+
/**
|
|
219
|
+
@internal
|
|
220
|
+
*/
|
|
221
|
+
startSide: number,
|
|
222
|
+
/**
|
|
223
|
+
@internal
|
|
224
|
+
*/
|
|
225
|
+
endSide: number,
|
|
226
|
+
/**
|
|
227
|
+
@internal
|
|
228
|
+
*/
|
|
229
|
+
widget: WidgetType | null,
|
|
230
|
+
/**
|
|
231
|
+
The config object used to create this decoration. You can
|
|
232
|
+
include additional properties in there to store metadata about
|
|
233
|
+
your decoration.
|
|
234
|
+
*/
|
|
235
|
+
spec: any);
|
|
217
236
|
abstract eq(other: Decoration): boolean;
|
|
218
237
|
/**
|
|
219
238
|
Create a mark decoration, which influences the styling of the
|
|
@@ -324,10 +343,10 @@ interface PluginSpec<V extends PluginValue> {
|
|
|
324
343
|
provide?: (plugin: ViewPlugin<V>) => Extension;
|
|
325
344
|
/**
|
|
326
345
|
Allow the plugin to provide decorations. When given, this should
|
|
327
|
-
a function that take the plugin value and return a
|
|
328
|
-
set](https://codemirror.net/6/docs/ref/#view.DecorationSet). See also the caveat about
|
|
329
|
-
[layout-changing decorations](https://codemirror.net/6/docs/ref/#view.EditorView^decorations)
|
|
330
|
-
|
|
346
|
+
be a function that take the plugin value and return a
|
|
347
|
+
[decoration set](https://codemirror.net/6/docs/ref/#view.DecorationSet). See also the caveat about
|
|
348
|
+
[layout-changing decorations](https://codemirror.net/6/docs/ref/#view.EditorView^decorations) that
|
|
349
|
+
depend on the view.
|
|
331
350
|
*/
|
|
332
351
|
decorations?: (value: V) => DecorationSet;
|
|
333
352
|
}
|
|
@@ -398,6 +417,7 @@ declare class ViewUpdate {
|
|
|
398
417
|
The previous editor state.
|
|
399
418
|
*/
|
|
400
419
|
readonly startState: EditorState;
|
|
420
|
+
private constructor();
|
|
401
421
|
/**
|
|
402
422
|
Tells you whether the [viewport](https://codemirror.net/6/docs/ref/#view.EditorView.viewport) or
|
|
403
423
|
[visible ranges](https://codemirror.net/6/docs/ref/#view.EditorView.visibleRanges) changed in this
|
|
@@ -968,8 +988,8 @@ declare class EditorView {
|
|
|
968
988
|
/**
|
|
969
989
|
By default, the editor assumes all its content has the same
|
|
970
990
|
[text direction](https://codemirror.net/6/docs/ref/#view.Direction). Configure this with a `true`
|
|
971
|
-
value to make it read
|
|
972
|
-
|
|
991
|
+
value to make it read the text direction of every (rendered)
|
|
992
|
+
line separately.
|
|
973
993
|
*/
|
|
974
994
|
static perLineTextDirection: Facet<boolean, boolean>;
|
|
975
995
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1152,9 +1152,6 @@ of content. You'll usually use it wrapped in a
|
|
|
1152
1152
|
@nonabstract
|
|
1153
1153
|
*/
|
|
1154
1154
|
class Decoration extends RangeValue {
|
|
1155
|
-
/**
|
|
1156
|
-
@internal
|
|
1157
|
-
*/
|
|
1158
1155
|
constructor(
|
|
1159
1156
|
/**
|
|
1160
1157
|
@internal
|
|
@@ -1699,7 +1696,6 @@ class NullWidget extends WidgetType {
|
|
|
1699
1696
|
updateDOM(elt) { return elt.nodeName.toLowerCase() == this.tag; }
|
|
1700
1697
|
}
|
|
1701
1698
|
|
|
1702
|
-
const none = [];
|
|
1703
1699
|
const clickAddsSelectionRange = /*@__PURE__*/Facet.define();
|
|
1704
1700
|
const dragMovesSelection$1 = /*@__PURE__*/Facet.define();
|
|
1705
1701
|
const mouseSelectionStyle = /*@__PURE__*/Facet.define();
|
|
@@ -1918,9 +1914,6 @@ View [plugins](https://codemirror.net/6/docs/ref/#view.ViewPlugin) are given ins
|
|
|
1918
1914
|
class, which describe what happened, whenever the view is updated.
|
|
1919
1915
|
*/
|
|
1920
1916
|
class ViewUpdate {
|
|
1921
|
-
/**
|
|
1922
|
-
@internal
|
|
1923
|
-
*/
|
|
1924
1917
|
constructor(
|
|
1925
1918
|
/**
|
|
1926
1919
|
The editor view that the update is associated with.
|
|
@@ -1933,7 +1926,7 @@ class ViewUpdate {
|
|
|
1933
1926
|
/**
|
|
1934
1927
|
The transactions involved in the update. May be empty.
|
|
1935
1928
|
*/
|
|
1936
|
-
transactions
|
|
1929
|
+
transactions) {
|
|
1937
1930
|
this.view = view;
|
|
1938
1931
|
this.state = state;
|
|
1939
1932
|
this.transactions = transactions;
|
|
@@ -1955,6 +1948,12 @@ class ViewUpdate {
|
|
|
1955
1948
|
}
|
|
1956
1949
|
}
|
|
1957
1950
|
/**
|
|
1951
|
+
@internal
|
|
1952
|
+
*/
|
|
1953
|
+
static create(view, state, transactions) {
|
|
1954
|
+
return new ViewUpdate(view, state, transactions);
|
|
1955
|
+
}
|
|
1956
|
+
/**
|
|
1958
1957
|
Tells you whether the [viewport](https://codemirror.net/6/docs/ref/#view.EditorView.viewport) or
|
|
1959
1958
|
[visible ranges](https://codemirror.net/6/docs/ref/#view.EditorView.visibleRanges) changed in this
|
|
1960
1959
|
update.
|
|
@@ -3839,11 +3838,16 @@ handlers.copy = handlers.cut = (view, event) => {
|
|
|
3839
3838
|
userEvent: "delete.cut"
|
|
3840
3839
|
});
|
|
3841
3840
|
};
|
|
3842
|
-
|
|
3841
|
+
function updateForFocusChange(view) {
|
|
3843
3842
|
setTimeout(() => {
|
|
3844
3843
|
if (view.hasFocus != view.inputState.notifiedFocused)
|
|
3845
3844
|
view.update([]);
|
|
3846
3845
|
}, 10);
|
|
3846
|
+
}
|
|
3847
|
+
handlers.focus = updateForFocusChange;
|
|
3848
|
+
handlers.blur = view => {
|
|
3849
|
+
view.observer.clearSelectionRange();
|
|
3850
|
+
updateForFocusChange(view);
|
|
3847
3851
|
};
|
|
3848
3852
|
function forceClearComposition(view, rapid) {
|
|
3849
3853
|
if (view.docView.compositionDeco.size) {
|
|
@@ -5480,6 +5484,9 @@ class DOMObserver {
|
|
|
5480
5484
|
this.selectionRange.set(anchor.node, anchor.offset, head.node, head.offset);
|
|
5481
5485
|
this.selectionChanged = false;
|
|
5482
5486
|
}
|
|
5487
|
+
clearSelectionRange() {
|
|
5488
|
+
this.selectionRange.set(null, 0, null, 0);
|
|
5489
|
+
}
|
|
5483
5490
|
listenForScroll() {
|
|
5484
5491
|
this.parentCheck = -1;
|
|
5485
5492
|
let i = 0, changed = null;
|
|
@@ -5759,6 +5766,11 @@ function applyDOMChange(view, start, end, typeOver) {
|
|
|
5759
5766
|
from: sel.from, to: sel.to,
|
|
5760
5767
|
insert: view.state.doc.slice(sel.from, change.from).append(change.insert).append(view.state.doc.slice(change.to, sel.to))
|
|
5761
5768
|
};
|
|
5769
|
+
// Detect insert-period-on-double-space Mac behavior, and transform
|
|
5770
|
+
// it into a regular space insert.
|
|
5771
|
+
else if (browser.mac && change && change.from == change.to && change.from == sel.head - 1 &&
|
|
5772
|
+
change.insert.toString() == ".")
|
|
5773
|
+
change = { from: sel.from, to: sel.to, insert: Text.of([" "]) };
|
|
5762
5774
|
if (change) {
|
|
5763
5775
|
let startState = view.state;
|
|
5764
5776
|
if (browser.ios && view.inputState.flushIOSKey(view))
|
|
@@ -6047,7 +6059,7 @@ class EditorView {
|
|
|
6047
6059
|
// When the phrases change, redraw the editor
|
|
6048
6060
|
if (state.facet(EditorState.phrases) != this.state.facet(EditorState.phrases))
|
|
6049
6061
|
return this.setState(state);
|
|
6050
|
-
update =
|
|
6062
|
+
update = ViewUpdate.create(this, state, transactions);
|
|
6051
6063
|
let scrollTarget = this.viewState.scrollTarget;
|
|
6052
6064
|
try {
|
|
6053
6065
|
this.updateState = 2 /* Updating */;
|
|
@@ -6190,7 +6202,7 @@ class EditorView {
|
|
|
6190
6202
|
return BadMeasure;
|
|
6191
6203
|
}
|
|
6192
6204
|
});
|
|
6193
|
-
let update =
|
|
6205
|
+
let update = ViewUpdate.create(this, this.state, []), redrawn = false, scrolled = false;
|
|
6194
6206
|
update.flags |= changed;
|
|
6195
6207
|
if (!updated)
|
|
6196
6208
|
updated = update;
|
|
@@ -6650,8 +6662,8 @@ EditorView.inputHandler = inputHandler;
|
|
|
6650
6662
|
/**
|
|
6651
6663
|
By default, the editor assumes all its content has the same
|
|
6652
6664
|
[text direction](https://codemirror.net/6/docs/ref/#view.Direction). Configure this with a `true`
|
|
6653
|
-
value to make it read
|
|
6654
|
-
|
|
6665
|
+
value to make it read the text direction of every (rendered)
|
|
6666
|
+
line separately.
|
|
6655
6667
|
*/
|
|
6656
6668
|
EditorView.perLineTextDirection = perLineTextDirection;
|
|
6657
6669
|
/**
|