@codemirror/view 0.20.3 → 0.20.6

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 CHANGED
@@ -1,3 +1,25 @@
1
+ ## 0.20.6 (2022-05-20)
2
+
3
+ ### Bug fixes
4
+
5
+ Make sure the editor re-measures itself when its attributes are updated.
6
+
7
+ ## 0.20.5 (2022-05-18)
8
+
9
+ ### Bug fixes
10
+
11
+ Fix an issue where gutter elements without any markers in them would not get the `cm-gutterElement` class assigned.
12
+
13
+ Fix an issue where DOM event handlers registered by plugins were retained indefinitely, even after the editor was reconfigured.
14
+
15
+ ## 0.20.4 (2022-05-03)
16
+
17
+ ### Bug fixes
18
+
19
+ Prevent Mac-style behavior of inserting a period when the user inserts two spaces.
20
+
21
+ 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.
22
+
1
23
  ## 0.20.3 (2022-04-27)
2
24
 
3
25
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -1063,14 +1063,16 @@ function attrsEq(a, b) {
1063
1063
  return true;
1064
1064
  }
1065
1065
  function updateAttrs(dom, prev, attrs) {
1066
+ let changed = null;
1066
1067
  if (prev)
1067
1068
  for (let name in prev)
1068
1069
  if (!(attrs && name in attrs))
1069
- dom.removeAttribute(name);
1070
+ dom.removeAttribute(changed = name);
1070
1071
  if (attrs)
1071
1072
  for (let name in attrs)
1072
1073
  if (!(prev && prev[name] == attrs[name]))
1073
- dom.setAttribute(name, attrs[name]);
1074
+ dom.setAttribute(changed = name, attrs[name]);
1075
+ return !!changed;
1074
1076
  }
1075
1077
 
1076
1078
  /**
@@ -1157,9 +1159,6 @@ of content. You'll usually use it wrapped in a
1157
1159
  @nonabstract
1158
1160
  */
1159
1161
  class Decoration extends state.RangeValue {
1160
- /**
1161
- @internal
1162
- */
1163
1162
  constructor(
1164
1163
  /**
1165
1164
  @internal
@@ -1704,7 +1703,6 @@ class NullWidget extends WidgetType {
1704
1703
  updateDOM(elt) { return elt.nodeName.toLowerCase() == this.tag; }
1705
1704
  }
1706
1705
 
1707
- const none = [];
1708
1706
  const clickAddsSelectionRange = state.Facet.define();
1709
1707
  const dragMovesSelection$1 = state.Facet.define();
1710
1708
  const mouseSelectionStyle = state.Facet.define();
@@ -1923,9 +1921,6 @@ View [plugins](https://codemirror.net/6/docs/ref/#view.ViewPlugin) are given ins
1923
1921
  class, which describe what happened, whenever the view is updated.
1924
1922
  */
1925
1923
  class ViewUpdate {
1926
- /**
1927
- @internal
1928
- */
1929
1924
  constructor(
1930
1925
  /**
1931
1926
  The editor view that the update is associated with.
@@ -1938,7 +1933,7 @@ class ViewUpdate {
1938
1933
  /**
1939
1934
  The transactions involved in the update. May be empty.
1940
1935
  */
1941
- transactions = none) {
1936
+ transactions) {
1942
1937
  this.view = view;
1943
1938
  this.state = state$1;
1944
1939
  this.transactions = transactions;
@@ -1960,6 +1955,12 @@ class ViewUpdate {
1960
1955
  }
1961
1956
  }
1962
1957
  /**
1958
+ @internal
1959
+ */
1960
+ static create(view, state, transactions) {
1961
+ return new ViewUpdate(view, state, transactions);
1962
+ }
1963
+ /**
1963
1964
  Tells you whether the [viewport](https://codemirror.net/6/docs/ref/#view.EditorView.viewport) or
1964
1965
  [visible ranges](https://codemirror.net/6/docs/ref/#view.EditorView.visibleRanges) changed in this
1965
1966
  update.
@@ -3320,6 +3321,7 @@ class InputState {
3320
3321
  ensureHandlers(view, plugins) {
3321
3322
  var _a;
3322
3323
  let handlers;
3324
+ this.customHandlers = [];
3323
3325
  for (let plugin of plugins)
3324
3326
  if (handlers = (_a = plugin.update(view).spec) === null || _a === void 0 ? void 0 : _a.domEventHandlers) {
3325
3327
  this.customHandlers.push({ plugin: plugin.value, handlers });
@@ -3845,11 +3847,16 @@ handlers.copy = handlers.cut = (view, event) => {
3845
3847
  userEvent: "delete.cut"
3846
3848
  });
3847
3849
  };
3848
- handlers.focus = handlers.blur = view => {
3850
+ function updateForFocusChange(view) {
3849
3851
  setTimeout(() => {
3850
3852
  if (view.hasFocus != view.inputState.notifiedFocused)
3851
3853
  view.update([]);
3852
3854
  }, 10);
3855
+ }
3856
+ handlers.focus = updateForFocusChange;
3857
+ handlers.blur = view => {
3858
+ view.observer.clearSelectionRange();
3859
+ updateForFocusChange(view);
3853
3860
  };
3854
3861
  function forceClearComposition(view, rapid) {
3855
3862
  if (view.docView.compositionDeco.size) {
@@ -4742,24 +4749,22 @@ class ViewState {
4742
4749
  this.defaultTextDirection = style.direction == "rtl" ? exports.Direction.RTL : exports.Direction.LTR;
4743
4750
  let refresh = this.heightOracle.mustRefreshForWrapping(whiteSpace);
4744
4751
  let measureContent = refresh || this.mustMeasureContent || this.contentDOMHeight != dom.clientHeight;
4752
+ this.contentDOMHeight = dom.clientHeight;
4753
+ this.mustMeasureContent = false;
4745
4754
  let result = 0, bias = 0;
4755
+ // Vertical padding
4756
+ let paddingTop = parseInt(style.paddingTop) || 0, paddingBottom = parseInt(style.paddingBottom) || 0;
4757
+ if (this.paddingTop != paddingTop || this.paddingBottom != paddingBottom) {
4758
+ this.paddingTop = paddingTop;
4759
+ this.paddingBottom = paddingBottom;
4760
+ result |= 8 /* Geometry */ | 2 /* Height */;
4761
+ }
4746
4762
  if (this.editorWidth != view.scrollDOM.clientWidth) {
4747
4763
  if (oracle.lineWrapping)
4748
4764
  measureContent = true;
4749
4765
  this.editorWidth = view.scrollDOM.clientWidth;
4750
4766
  result |= 8 /* Geometry */;
4751
4767
  }
4752
- if (measureContent) {
4753
- this.mustMeasureContent = false;
4754
- this.contentDOMHeight = dom.clientHeight;
4755
- // Vertical padding
4756
- let paddingTop = parseInt(style.paddingTop) || 0, paddingBottom = parseInt(style.paddingBottom) || 0;
4757
- if (this.paddingTop != paddingTop || this.paddingBottom != paddingBottom) {
4758
- result |= 8 /* Geometry */;
4759
- this.paddingTop = paddingTop;
4760
- this.paddingBottom = paddingBottom;
4761
- }
4762
- }
4763
4768
  // Pixel viewport
4764
4769
  let pixelViewport = (this.printing ? fullPixelRange : visiblePixelRange)(dom, this.paddingTop);
4765
4770
  let dTop = pixelViewport.top - this.pixelViewport.top, dBottom = pixelViewport.bottom - this.pixelViewport.bottom;
@@ -5487,6 +5492,9 @@ class DOMObserver {
5487
5492
  this.selectionRange.set(anchor.node, anchor.offset, head.node, head.offset);
5488
5493
  this.selectionChanged = false;
5489
5494
  }
5495
+ clearSelectionRange() {
5496
+ this.selectionRange.set(null, 0, null, 0);
5497
+ }
5490
5498
  listenForScroll() {
5491
5499
  this.parentCheck = -1;
5492
5500
  let i = 0, changed = null;
@@ -5766,6 +5774,11 @@ function applyDOMChange(view, start, end, typeOver) {
5766
5774
  from: sel.from, to: sel.to,
5767
5775
  insert: view.state.doc.slice(sel.from, change.from).append(change.insert).append(view.state.doc.slice(change.to, sel.to))
5768
5776
  };
5777
+ // Detect insert-period-on-double-space Mac behavior, and transform
5778
+ // it into a regular space insert.
5779
+ else if (browser.mac && change && change.from == change.to && change.from == sel.head - 1 &&
5780
+ change.insert.toString() == ".")
5781
+ change = { from: sel.from, to: sel.to, insert: state.Text.of([" "]) };
5769
5782
  if (change) {
5770
5783
  let startState = view.state;
5771
5784
  if (browser.ios && view.inputState.flushIOSKey(view))
@@ -6040,7 +6053,7 @@ class EditorView {
6040
6053
  update(transactions) {
6041
6054
  if (this.updateState != 0 /* Idle */)
6042
6055
  throw new Error("Calls to EditorView.update are not allowed while an update is in progress");
6043
- let redrawn = false, update;
6056
+ let redrawn = false, attrsChanged = false, update;
6044
6057
  let state$1 = this.state;
6045
6058
  for (let tr of transactions) {
6046
6059
  if (tr.startState != state$1)
@@ -6054,7 +6067,7 @@ class EditorView {
6054
6067
  // When the phrases change, redraw the editor
6055
6068
  if (state$1.facet(state.EditorState.phrases) != this.state.facet(state.EditorState.phrases))
6056
6069
  return this.setState(state$1);
6057
- update = new ViewUpdate(this, state$1, transactions);
6070
+ update = ViewUpdate.create(this, state$1, transactions);
6058
6071
  let scrollTarget = this.viewState.scrollTarget;
6059
6072
  try {
6060
6073
  this.updateState = 2 /* Updating */;
@@ -6078,7 +6091,7 @@ class EditorView {
6078
6091
  redrawn = this.docView.update(update);
6079
6092
  if (this.state.facet(styleModule) != this.styleModules)
6080
6093
  this.mountStyles();
6081
- this.updateAttrs();
6094
+ attrsChanged = this.updateAttrs();
6082
6095
  this.showAnnouncements(transactions);
6083
6096
  this.docView.updateSelection(redrawn, transactions.some(tr => tr.isUserEvent("select.pointer")));
6084
6097
  }
@@ -6087,7 +6100,7 @@ class EditorView {
6087
6100
  }
6088
6101
  if (update.startState.facet(theme) != update.state.facet(theme))
6089
6102
  this.viewState.mustMeasureContent = true;
6090
- if (redrawn || scrollTarget || this.viewState.mustEnforceCursorAssoc || this.viewState.mustMeasureContent)
6103
+ if (redrawn || attrsChanged || scrollTarget || this.viewState.mustEnforceCursorAssoc || this.viewState.mustMeasureContent)
6091
6104
  this.requestMeasure();
6092
6105
  if (!update.empty)
6093
6106
  for (let listener of this.state.facet(updateListener))
@@ -6197,7 +6210,7 @@ class EditorView {
6197
6210
  return BadMeasure;
6198
6211
  }
6199
6212
  });
6200
- let update = new ViewUpdate(this, this.state), redrawn = false, scrolled = false;
6213
+ let update = ViewUpdate.create(this, this.state, []), redrawn = false, scrolled = false;
6201
6214
  update.flags |= changed;
6202
6215
  if (!updated)
6203
6216
  updated = update;
@@ -6267,12 +6280,14 @@ class EditorView {
6267
6280
  if (this.state.readOnly)
6268
6281
  contentAttrs["aria-readonly"] = "true";
6269
6282
  attrsFromFacet(this, contentAttributes, contentAttrs);
6270
- this.observer.ignore(() => {
6271
- updateAttrs(this.contentDOM, this.contentAttrs, contentAttrs);
6272
- updateAttrs(this.dom, this.editorAttrs, editorAttrs);
6283
+ let changed = this.observer.ignore(() => {
6284
+ let changedContent = updateAttrs(this.contentDOM, this.contentAttrs, contentAttrs);
6285
+ let changedEditor = updateAttrs(this.dom, this.editorAttrs, editorAttrs);
6286
+ return changedContent || changedEditor;
6273
6287
  });
6274
6288
  this.editorAttrs = editorAttrs;
6275
6289
  this.contentAttrs = contentAttrs;
6290
+ return changed;
6276
6291
  }
6277
6292
  showAnnouncements(trs) {
6278
6293
  let first = true;
@@ -6657,8 +6672,8 @@ EditorView.inputHandler = inputHandler;
6657
6672
  /**
6658
6673
  By default, the editor assumes all its content has the same
6659
6674
  [text direction](https://codemirror.net/6/docs/ref/#view.Direction). Configure this with a `true`
6660
- value to make it read and store the text direction of every
6661
- (rendered) line separately.
6675
+ value to make it read the text direction of every (rendered)
6676
+ line separately.
6662
6677
  */
6663
6678
  EditorView.perLineTextDirection = perLineTextDirection;
6664
6679
  /**
@@ -8169,7 +8184,6 @@ class HoverPlugin {
8169
8184
  this.startHover();
8170
8185
  }
8171
8186
  startHover() {
8172
- var _a;
8173
8187
  clearTimeout(this.restartTimeout);
8174
8188
  let { lastMove } = this;
8175
8189
  let pos = this.view.contentDOM.contains(lastMove.target) ? this.view.posAtCoords(lastMove) : null;
@@ -8183,7 +8197,7 @@ class HoverPlugin {
8183
8197
  let bidi = this.view.bidiSpans(this.view.state.doc.lineAt(pos)).find(s => s.from <= pos && s.to >= pos);
8184
8198
  let rtl = bidi && bidi.dir == exports.Direction.RTL ? -1 : 1;
8185
8199
  let open = this.source(this.view, pos, (lastMove.x < posCoords.left ? -rtl : rtl));
8186
- if ((_a = open) === null || _a === void 0 ? void 0 : _a.then) {
8200
+ if (open === null || open === void 0 ? void 0 : open.then) {
8187
8201
  let pending = this.pending = { pos };
8188
8202
  open.then(result => {
8189
8203
  if (this.pending == pending) {
@@ -8783,6 +8797,7 @@ class GutterElement {
8783
8797
  this.above = 0;
8784
8798
  this.markers = [];
8785
8799
  this.dom = document.createElement("div");
8800
+ this.dom.className = "cm-gutterElement";
8786
8801
  this.update(view, height, above, markers);
8787
8802
  }
8788
8803
  update(view, height, above, markers) {
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 [decoration
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
- that depend on the view.
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 and store the text direction of every
972
- (rendered) line separately.
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
@@ -1059,14 +1059,16 @@ function attrsEq(a, b) {
1059
1059
  return true;
1060
1060
  }
1061
1061
  function updateAttrs(dom, prev, attrs) {
1062
+ let changed = null;
1062
1063
  if (prev)
1063
1064
  for (let name in prev)
1064
1065
  if (!(attrs && name in attrs))
1065
- dom.removeAttribute(name);
1066
+ dom.removeAttribute(changed = name);
1066
1067
  if (attrs)
1067
1068
  for (let name in attrs)
1068
1069
  if (!(prev && prev[name] == attrs[name]))
1069
- dom.setAttribute(name, attrs[name]);
1070
+ dom.setAttribute(changed = name, attrs[name]);
1071
+ return !!changed;
1070
1072
  }
1071
1073
 
1072
1074
  /**
@@ -1152,9 +1154,6 @@ of content. You'll usually use it wrapped in a
1152
1154
  @nonabstract
1153
1155
  */
1154
1156
  class Decoration extends RangeValue {
1155
- /**
1156
- @internal
1157
- */
1158
1157
  constructor(
1159
1158
  /**
1160
1159
  @internal
@@ -1699,7 +1698,6 @@ class NullWidget extends WidgetType {
1699
1698
  updateDOM(elt) { return elt.nodeName.toLowerCase() == this.tag; }
1700
1699
  }
1701
1700
 
1702
- const none = [];
1703
1701
  const clickAddsSelectionRange = /*@__PURE__*/Facet.define();
1704
1702
  const dragMovesSelection$1 = /*@__PURE__*/Facet.define();
1705
1703
  const mouseSelectionStyle = /*@__PURE__*/Facet.define();
@@ -1918,9 +1916,6 @@ View [plugins](https://codemirror.net/6/docs/ref/#view.ViewPlugin) are given ins
1918
1916
  class, which describe what happened, whenever the view is updated.
1919
1917
  */
1920
1918
  class ViewUpdate {
1921
- /**
1922
- @internal
1923
- */
1924
1919
  constructor(
1925
1920
  /**
1926
1921
  The editor view that the update is associated with.
@@ -1933,7 +1928,7 @@ class ViewUpdate {
1933
1928
  /**
1934
1929
  The transactions involved in the update. May be empty.
1935
1930
  */
1936
- transactions = none) {
1931
+ transactions) {
1937
1932
  this.view = view;
1938
1933
  this.state = state;
1939
1934
  this.transactions = transactions;
@@ -1955,6 +1950,12 @@ class ViewUpdate {
1955
1950
  }
1956
1951
  }
1957
1952
  /**
1953
+ @internal
1954
+ */
1955
+ static create(view, state, transactions) {
1956
+ return new ViewUpdate(view, state, transactions);
1957
+ }
1958
+ /**
1958
1959
  Tells you whether the [viewport](https://codemirror.net/6/docs/ref/#view.EditorView.viewport) or
1959
1960
  [visible ranges](https://codemirror.net/6/docs/ref/#view.EditorView.visibleRanges) changed in this
1960
1961
  update.
@@ -3314,6 +3315,7 @@ class InputState {
3314
3315
  ensureHandlers(view, plugins) {
3315
3316
  var _a;
3316
3317
  let handlers;
3318
+ this.customHandlers = [];
3317
3319
  for (let plugin of plugins)
3318
3320
  if (handlers = (_a = plugin.update(view).spec) === null || _a === void 0 ? void 0 : _a.domEventHandlers) {
3319
3321
  this.customHandlers.push({ plugin: plugin.value, handlers });
@@ -3839,11 +3841,16 @@ handlers.copy = handlers.cut = (view, event) => {
3839
3841
  userEvent: "delete.cut"
3840
3842
  });
3841
3843
  };
3842
- handlers.focus = handlers.blur = view => {
3844
+ function updateForFocusChange(view) {
3843
3845
  setTimeout(() => {
3844
3846
  if (view.hasFocus != view.inputState.notifiedFocused)
3845
3847
  view.update([]);
3846
3848
  }, 10);
3849
+ }
3850
+ handlers.focus = updateForFocusChange;
3851
+ handlers.blur = view => {
3852
+ view.observer.clearSelectionRange();
3853
+ updateForFocusChange(view);
3847
3854
  };
3848
3855
  function forceClearComposition(view, rapid) {
3849
3856
  if (view.docView.compositionDeco.size) {
@@ -4735,24 +4742,22 @@ class ViewState {
4735
4742
  this.defaultTextDirection = style.direction == "rtl" ? Direction.RTL : Direction.LTR;
4736
4743
  let refresh = this.heightOracle.mustRefreshForWrapping(whiteSpace);
4737
4744
  let measureContent = refresh || this.mustMeasureContent || this.contentDOMHeight != dom.clientHeight;
4745
+ this.contentDOMHeight = dom.clientHeight;
4746
+ this.mustMeasureContent = false;
4738
4747
  let result = 0, bias = 0;
4748
+ // Vertical padding
4749
+ let paddingTop = parseInt(style.paddingTop) || 0, paddingBottom = parseInt(style.paddingBottom) || 0;
4750
+ if (this.paddingTop != paddingTop || this.paddingBottom != paddingBottom) {
4751
+ this.paddingTop = paddingTop;
4752
+ this.paddingBottom = paddingBottom;
4753
+ result |= 8 /* Geometry */ | 2 /* Height */;
4754
+ }
4739
4755
  if (this.editorWidth != view.scrollDOM.clientWidth) {
4740
4756
  if (oracle.lineWrapping)
4741
4757
  measureContent = true;
4742
4758
  this.editorWidth = view.scrollDOM.clientWidth;
4743
4759
  result |= 8 /* Geometry */;
4744
4760
  }
4745
- if (measureContent) {
4746
- this.mustMeasureContent = false;
4747
- this.contentDOMHeight = dom.clientHeight;
4748
- // Vertical padding
4749
- let paddingTop = parseInt(style.paddingTop) || 0, paddingBottom = parseInt(style.paddingBottom) || 0;
4750
- if (this.paddingTop != paddingTop || this.paddingBottom != paddingBottom) {
4751
- result |= 8 /* Geometry */;
4752
- this.paddingTop = paddingTop;
4753
- this.paddingBottom = paddingBottom;
4754
- }
4755
- }
4756
4761
  // Pixel viewport
4757
4762
  let pixelViewport = (this.printing ? fullPixelRange : visiblePixelRange)(dom, this.paddingTop);
4758
4763
  let dTop = pixelViewport.top - this.pixelViewport.top, dBottom = pixelViewport.bottom - this.pixelViewport.bottom;
@@ -5480,6 +5485,9 @@ class DOMObserver {
5480
5485
  this.selectionRange.set(anchor.node, anchor.offset, head.node, head.offset);
5481
5486
  this.selectionChanged = false;
5482
5487
  }
5488
+ clearSelectionRange() {
5489
+ this.selectionRange.set(null, 0, null, 0);
5490
+ }
5483
5491
  listenForScroll() {
5484
5492
  this.parentCheck = -1;
5485
5493
  let i = 0, changed = null;
@@ -5759,6 +5767,11 @@ function applyDOMChange(view, start, end, typeOver) {
5759
5767
  from: sel.from, to: sel.to,
5760
5768
  insert: view.state.doc.slice(sel.from, change.from).append(change.insert).append(view.state.doc.slice(change.to, sel.to))
5761
5769
  };
5770
+ // Detect insert-period-on-double-space Mac behavior, and transform
5771
+ // it into a regular space insert.
5772
+ else if (browser.mac && change && change.from == change.to && change.from == sel.head - 1 &&
5773
+ change.insert.toString() == ".")
5774
+ change = { from: sel.from, to: sel.to, insert: Text.of([" "]) };
5762
5775
  if (change) {
5763
5776
  let startState = view.state;
5764
5777
  if (browser.ios && view.inputState.flushIOSKey(view))
@@ -6033,7 +6046,7 @@ class EditorView {
6033
6046
  update(transactions) {
6034
6047
  if (this.updateState != 0 /* Idle */)
6035
6048
  throw new Error("Calls to EditorView.update are not allowed while an update is in progress");
6036
- let redrawn = false, update;
6049
+ let redrawn = false, attrsChanged = false, update;
6037
6050
  let state = this.state;
6038
6051
  for (let tr of transactions) {
6039
6052
  if (tr.startState != state)
@@ -6047,7 +6060,7 @@ class EditorView {
6047
6060
  // When the phrases change, redraw the editor
6048
6061
  if (state.facet(EditorState.phrases) != this.state.facet(EditorState.phrases))
6049
6062
  return this.setState(state);
6050
- update = new ViewUpdate(this, state, transactions);
6063
+ update = ViewUpdate.create(this, state, transactions);
6051
6064
  let scrollTarget = this.viewState.scrollTarget;
6052
6065
  try {
6053
6066
  this.updateState = 2 /* Updating */;
@@ -6071,7 +6084,7 @@ class EditorView {
6071
6084
  redrawn = this.docView.update(update);
6072
6085
  if (this.state.facet(styleModule) != this.styleModules)
6073
6086
  this.mountStyles();
6074
- this.updateAttrs();
6087
+ attrsChanged = this.updateAttrs();
6075
6088
  this.showAnnouncements(transactions);
6076
6089
  this.docView.updateSelection(redrawn, transactions.some(tr => tr.isUserEvent("select.pointer")));
6077
6090
  }
@@ -6080,7 +6093,7 @@ class EditorView {
6080
6093
  }
6081
6094
  if (update.startState.facet(theme) != update.state.facet(theme))
6082
6095
  this.viewState.mustMeasureContent = true;
6083
- if (redrawn || scrollTarget || this.viewState.mustEnforceCursorAssoc || this.viewState.mustMeasureContent)
6096
+ if (redrawn || attrsChanged || scrollTarget || this.viewState.mustEnforceCursorAssoc || this.viewState.mustMeasureContent)
6084
6097
  this.requestMeasure();
6085
6098
  if (!update.empty)
6086
6099
  for (let listener of this.state.facet(updateListener))
@@ -6190,7 +6203,7 @@ class EditorView {
6190
6203
  return BadMeasure;
6191
6204
  }
6192
6205
  });
6193
- let update = new ViewUpdate(this, this.state), redrawn = false, scrolled = false;
6206
+ let update = ViewUpdate.create(this, this.state, []), redrawn = false, scrolled = false;
6194
6207
  update.flags |= changed;
6195
6208
  if (!updated)
6196
6209
  updated = update;
@@ -6260,12 +6273,14 @@ class EditorView {
6260
6273
  if (this.state.readOnly)
6261
6274
  contentAttrs["aria-readonly"] = "true";
6262
6275
  attrsFromFacet(this, contentAttributes, contentAttrs);
6263
- this.observer.ignore(() => {
6264
- updateAttrs(this.contentDOM, this.contentAttrs, contentAttrs);
6265
- updateAttrs(this.dom, this.editorAttrs, editorAttrs);
6276
+ let changed = this.observer.ignore(() => {
6277
+ let changedContent = updateAttrs(this.contentDOM, this.contentAttrs, contentAttrs);
6278
+ let changedEditor = updateAttrs(this.dom, this.editorAttrs, editorAttrs);
6279
+ return changedContent || changedEditor;
6266
6280
  });
6267
6281
  this.editorAttrs = editorAttrs;
6268
6282
  this.contentAttrs = contentAttrs;
6283
+ return changed;
6269
6284
  }
6270
6285
  showAnnouncements(trs) {
6271
6286
  let first = true;
@@ -6650,8 +6665,8 @@ EditorView.inputHandler = inputHandler;
6650
6665
  /**
6651
6666
  By default, the editor assumes all its content has the same
6652
6667
  [text direction](https://codemirror.net/6/docs/ref/#view.Direction). Configure this with a `true`
6653
- value to make it read and store the text direction of every
6654
- (rendered) line separately.
6668
+ value to make it read the text direction of every (rendered)
6669
+ line separately.
6655
6670
  */
6656
6671
  EditorView.perLineTextDirection = perLineTextDirection;
6657
6672
  /**
@@ -8162,7 +8177,6 @@ class HoverPlugin {
8162
8177
  this.startHover();
8163
8178
  }
8164
8179
  startHover() {
8165
- var _a;
8166
8180
  clearTimeout(this.restartTimeout);
8167
8181
  let { lastMove } = this;
8168
8182
  let pos = this.view.contentDOM.contains(lastMove.target) ? this.view.posAtCoords(lastMove) : null;
@@ -8176,7 +8190,7 @@ class HoverPlugin {
8176
8190
  let bidi = this.view.bidiSpans(this.view.state.doc.lineAt(pos)).find(s => s.from <= pos && s.to >= pos);
8177
8191
  let rtl = bidi && bidi.dir == Direction.RTL ? -1 : 1;
8178
8192
  let open = this.source(this.view, pos, (lastMove.x < posCoords.left ? -rtl : rtl));
8179
- if ((_a = open) === null || _a === void 0 ? void 0 : _a.then) {
8193
+ if (open === null || open === void 0 ? void 0 : open.then) {
8180
8194
  let pending = this.pending = { pos };
8181
8195
  open.then(result => {
8182
8196
  if (this.pending == pending) {
@@ -8776,6 +8790,7 @@ class GutterElement {
8776
8790
  this.above = 0;
8777
8791
  this.markers = [];
8778
8792
  this.dom = document.createElement("div");
8793
+ this.dom.className = "cm-gutterElement";
8779
8794
  this.update(view, height, above, markers);
8780
8795
  }
8781
8796
  update(view, height, above, markers) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/view",
3
- "version": "0.20.3",
3
+ "version": "0.20.6",
4
4
  "description": "DOM view component for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",