@codemirror/lint 0.19.3 → 0.19.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 CHANGED
@@ -1,3 +1,13 @@
1
+ ## 0.19.4 (2022-02-25)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue where an outdated marker could stick around on the lint gutter after all diagnostics were removed.
6
+
7
+ ### New features
8
+
9
+ Add a `hoverTime` option to the lint gutter. Change default hover time to 300
10
+
1
11
  ## 0.19.3 (2021-11-09)
2
12
 
3
13
  ### New features
package/dist/index.cjs CHANGED
@@ -143,7 +143,7 @@ function lintTooltip(view, pos, side) {
143
143
  };
144
144
  }
145
145
  function diagnosticsTooltip(view, diagnostics) {
146
- return elt__default['default']("ul", { class: "cm-tooltip-lint" }, diagnostics.map(d => renderDiagnostic(view, d, false)));
146
+ return elt__default["default"]("ul", { class: "cm-tooltip-lint" }, diagnostics.map(d => renderDiagnostic(view, d, false)));
147
147
  }
148
148
  /**
149
149
  Command to open and focus the lint panel.
@@ -212,10 +212,8 @@ const lintPlugin = view.ViewPlugin.fromClass(class {
212
212
  this.set = false;
213
213
  let { state } = this.view, { sources } = state.facet(lintSource);
214
214
  Promise.all(sources.map(source => Promise.resolve(source(this.view)))).then(annotations => {
215
- var _a, _b;
216
215
  let all = annotations.reduce((a, b) => a.concat(b));
217
- if (this.view.state.doc == state.doc &&
218
- (all.length || ((_b = (_a = this.view.state.field(lintState, false)) === null || _a === void 0 ? void 0 : _a.diagnostics) === null || _b === void 0 ? void 0 : _b.size)))
216
+ if (this.view.state.doc == state.doc)
219
217
  this.view.dispatch(setDiagnostics(this.view.state, all));
220
218
  }, error => { view.logException(this.view.state, error); });
221
219
  }
@@ -282,7 +280,7 @@ function assignKeys(actions) {
282
280
  function renderDiagnostic(view, diagnostic, inPanel) {
283
281
  var _a;
284
282
  let keys = inPanel ? assignKeys(diagnostic.actions) : [];
285
- return elt__default['default']("li", { class: "cm-diagnostic cm-diagnostic-" + diagnostic.severity }, elt__default['default']("span", { class: "cm-diagnosticText" }, diagnostic.message), (_a = diagnostic.actions) === null || _a === void 0 ? void 0 : _a.map((action, i) => {
283
+ return elt__default["default"]("li", { class: "cm-diagnostic cm-diagnostic-" + diagnostic.severity }, elt__default["default"]("span", { class: "cm-diagnosticText" }, diagnostic.message), (_a = diagnostic.actions) === null || _a === void 0 ? void 0 : _a.map((action, i) => {
286
284
  let click = (e) => {
287
285
  e.preventDefault();
288
286
  let found = findDiagnostic(view.state.field(lintState).diagnostics, diagnostic);
@@ -291,16 +289,16 @@ function renderDiagnostic(view, diagnostic, inPanel) {
291
289
  };
292
290
  let { name } = action, keyIndex = keys[i] ? name.indexOf(keys[i]) : -1;
293
291
  let nameElt = keyIndex < 0 ? name : [name.slice(0, keyIndex),
294
- elt__default['default']("u", name.slice(keyIndex, keyIndex + 1)),
292
+ elt__default["default"]("u", name.slice(keyIndex, keyIndex + 1)),
295
293
  name.slice(keyIndex + 1)];
296
- return elt__default['default']("button", {
294
+ return elt__default["default"]("button", {
297
295
  type: "button",
298
296
  class: "cm-diagnosticAction",
299
297
  onclick: click,
300
298
  onmousedown: click,
301
299
  "aria-label": ` Action: ${name}${keyIndex < 0 ? "" : ` (access key "${keys[i]})"`}.`
302
300
  }, nameElt);
303
- }), diagnostic.source && elt__default['default']("div", { class: "cm-diagnosticSource" }, diagnostic.source));
301
+ }), diagnostic.source && elt__default["default"]("div", { class: "cm-diagnosticSource" }, diagnostic.source));
304
302
  }
305
303
  class DiagnosticWidget extends view.WidgetType {
306
304
  constructor(diagnostic) {
@@ -309,7 +307,7 @@ class DiagnosticWidget extends view.WidgetType {
309
307
  }
310
308
  eq(other) { return other.diagnostic == this.diagnostic; }
311
309
  toDOM() {
312
- return elt__default['default']("span", { class: "cm-lintPoint cm-lintPoint-" + this.diagnostic.severity });
310
+ return elt__default["default"]("span", { class: "cm-lintPoint cm-lintPoint-" + this.diagnostic.severity });
313
311
  }
314
312
  }
315
313
  class PanelItem {
@@ -365,14 +363,14 @@ class LintPanel {
365
363
  this.moveSelection(i);
366
364
  }
367
365
  };
368
- this.list = elt__default['default']("ul", {
366
+ this.list = elt__default["default"]("ul", {
369
367
  tabIndex: 0,
370
368
  role: "listbox",
371
369
  "aria-label": this.view.state.phrase("Diagnostics"),
372
370
  onkeydown,
373
371
  onclick
374
372
  });
375
- this.dom = elt__default['default']("div", { class: "cm-panel-lint" }, this.list, elt__default['default']("button", {
373
+ this.dom = elt__default["default"]("div", { class: "cm-panel-lint" }, this.list, elt__default["default"]("button", {
376
374
  type: "button",
377
375
  name: "close",
378
376
  "aria-label": this.view.state.phrase("close"),
@@ -613,7 +611,7 @@ function trackHoverOn(view, marker) {
613
611
  }
614
612
  function gutterMarkerMouseOver(view, marker, diagnostics) {
615
613
  function hovered() {
616
- let line = view.visualLineAtHeight(marker.getBoundingClientRect().top + 5);
614
+ let line = view.visualLineAtHeight(marker.getBoundingClientRect().top + 5 - view.documentTop);
617
615
  const linePos = view.coordsAtPos(line.from), markerRect = marker.getBoundingClientRect();
618
616
  if (linePos) {
619
617
  view.dispatch({ effects: setLintGutterTooltip.of({
@@ -630,14 +628,15 @@ function gutterMarkerMouseOver(view, marker, diagnostics) {
630
628
  marker.onmouseout = marker.onmousemove = null;
631
629
  trackHoverOn(view, marker);
632
630
  }
633
- let hoverTimeout = setTimeout(hovered, 600 /* Time */);
631
+ let { hoverTime } = view.state.facet(lintGutterConfig);
632
+ let hoverTimeout = setTimeout(hovered, hoverTime);
634
633
  marker.onmouseout = () => {
635
634
  clearTimeout(hoverTimeout);
636
635
  marker.onmouseout = marker.onmousemove = null;
637
636
  };
638
637
  marker.onmousemove = () => {
639
638
  clearTimeout(hoverTimeout);
640
- hoverTimeout = setTimeout(hovered, 600 /* Time */);
639
+ hoverTimeout = setTimeout(hovered, hoverTime);
641
640
  };
642
641
  }
643
642
  function markersForDiagnostics(doc, diagnostics) {
@@ -703,13 +702,20 @@ const lintGutterTheme = view.EditorView.baseTheme({
703
702
  content: svg(`<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>`)
704
703
  },
705
704
  });
705
+ const lintGutterConfig = state.Facet.define({
706
+ combine(configs) {
707
+ return state.combineConfig(configs, {
708
+ hoverTime: 300 /* Time */,
709
+ });
710
+ }
711
+ });
706
712
  /**
707
713
  Returns an extension that installs a gutter showing markers for
708
714
  each line that has diagnostics, which can be hovered over to see
709
715
  the diagnostics.
710
716
  */
711
- function lintGutter() {
712
- return [lintGutterMarkers, lintGutterExtension, lintGutterTheme, lintGutterTooltip];
717
+ function lintGutter(config = {}) {
718
+ return [lintGutterConfig.of(config), lintGutterMarkers, lintGutterExtension, lintGutterTheme, lintGutterTooltip];
713
719
  }
714
720
 
715
721
  exports.closeLintPanel = closeLintPanel;
package/dist/index.d.ts CHANGED
@@ -51,6 +51,12 @@ interface Action {
51
51
  */
52
52
  apply: (view: EditorView, from: number, to: number) => void;
53
53
  }
54
+ interface LintGutterConfig {
55
+ /**
56
+ The delay before showing a tooltip when hovering over a lint gutter marker.
57
+ */
58
+ hoverTime?: number;
59
+ }
54
60
  /**
55
61
  Returns a transaction spec which updates the current set of
56
62
  diagnostics, and enables the lint extension if if wasn't already
@@ -108,6 +114,6 @@ Returns an extension that installs a gutter showing markers for
108
114
  each line that has diagnostics, which can be hovered over to see
109
115
  the diagnostics.
110
116
  */
111
- declare function lintGutter(): Extension;
117
+ declare function lintGutter(config?: LintGutterConfig): Extension;
112
118
 
113
119
  export { Action, Diagnostic, closeLintPanel, diagnosticCount, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, setDiagnostics, setDiagnosticsEffect };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Decoration, EditorView, ViewPlugin, logException, WidgetType } from '@codemirror/view';
2
- import { StateEffect, StateField, Facet } from '@codemirror/state';
2
+ import { StateEffect, StateField, Facet, combineConfig } from '@codemirror/state';
3
3
  import { hoverTooltip, showTooltip } from '@codemirror/tooltip';
4
4
  import { showPanel, getPanel } from '@codemirror/panel';
5
5
  import { gutter, GutterMarker } from '@codemirror/gutter';
@@ -204,10 +204,8 @@ const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
204
204
  this.set = false;
205
205
  let { state } = this.view, { sources } = state.facet(lintSource);
206
206
  Promise.all(sources.map(source => Promise.resolve(source(this.view)))).then(annotations => {
207
- var _a, _b;
208
207
  let all = annotations.reduce((a, b) => a.concat(b));
209
- if (this.view.state.doc == state.doc &&
210
- (all.length || ((_b = (_a = this.view.state.field(lintState, false)) === null || _a === void 0 ? void 0 : _a.diagnostics) === null || _b === void 0 ? void 0 : _b.size)))
208
+ if (this.view.state.doc == state.doc)
211
209
  this.view.dispatch(setDiagnostics(this.view.state, all));
212
210
  }, error => { logException(this.view.state, error); });
213
211
  }
@@ -605,7 +603,7 @@ function trackHoverOn(view, marker) {
605
603
  }
606
604
  function gutterMarkerMouseOver(view, marker, diagnostics) {
607
605
  function hovered() {
608
- let line = view.visualLineAtHeight(marker.getBoundingClientRect().top + 5);
606
+ let line = view.visualLineAtHeight(marker.getBoundingClientRect().top + 5 - view.documentTop);
609
607
  const linePos = view.coordsAtPos(line.from), markerRect = marker.getBoundingClientRect();
610
608
  if (linePos) {
611
609
  view.dispatch({ effects: setLintGutterTooltip.of({
@@ -622,14 +620,15 @@ function gutterMarkerMouseOver(view, marker, diagnostics) {
622
620
  marker.onmouseout = marker.onmousemove = null;
623
621
  trackHoverOn(view, marker);
624
622
  }
625
- let hoverTimeout = setTimeout(hovered, 600 /* Time */);
623
+ let { hoverTime } = view.state.facet(lintGutterConfig);
624
+ let hoverTimeout = setTimeout(hovered, hoverTime);
626
625
  marker.onmouseout = () => {
627
626
  clearTimeout(hoverTimeout);
628
627
  marker.onmouseout = marker.onmousemove = null;
629
628
  };
630
629
  marker.onmousemove = () => {
631
630
  clearTimeout(hoverTimeout);
632
- hoverTimeout = setTimeout(hovered, 600 /* Time */);
631
+ hoverTimeout = setTimeout(hovered, hoverTime);
633
632
  };
634
633
  }
635
634
  function markersForDiagnostics(doc, diagnostics) {
@@ -695,13 +694,20 @@ const lintGutterTheme = /*@__PURE__*/EditorView.baseTheme({
695
694
  content: /*@__PURE__*/svg(`<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>`)
696
695
  },
697
696
  });
697
+ const lintGutterConfig = /*@__PURE__*/Facet.define({
698
+ combine(configs) {
699
+ return combineConfig(configs, {
700
+ hoverTime: 300 /* Time */,
701
+ });
702
+ }
703
+ });
698
704
  /**
699
705
  Returns an extension that installs a gutter showing markers for
700
706
  each line that has diagnostics, which can be hovered over to see
701
707
  the diagnostics.
702
708
  */
703
- function lintGutter() {
704
- return [lintGutterMarkers, lintGutterExtension, lintGutterTheme, lintGutterTooltip];
709
+ function lintGutter(config = {}) {
710
+ return [lintGutterConfig.of(config), lintGutterMarkers, lintGutterExtension, lintGutterTheme, lintGutterTooltip];
705
711
  }
706
712
 
707
713
  export { closeLintPanel, diagnosticCount, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, setDiagnostics, setDiagnosticsEffect };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/lint",
3
- "version": "0.19.3",
3
+ "version": "0.19.4",
4
4
  "description": "Linting support for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",
@@ -31,7 +31,7 @@
31
31
  "@codemirror/rangeset": "^0.19.1",
32
32
  "@codemirror/state": "^0.19.4",
33
33
  "@codemirror/tooltip": "^0.19.5",
34
- "@codemirror/view": "^0.19.0",
34
+ "@codemirror/view": "^0.19.22",
35
35
  "crelt": "^1.0.5"
36
36
  },
37
37
  "devDependencies": {