@codemirror/lint 6.0.0 → 6.1.1

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.
@@ -11,6 +11,6 @@ jobs:
11
11
  with:
12
12
  # You should create a personal access token and store it in your repository
13
13
  token: ${{ secrets.DISPATCH_AUTH }}
14
- repo: codemirror.next
14
+ repo: dev
15
15
  owner: codemirror
16
16
  event_type: push
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 6.1.1 (2023-02-15)
2
+
3
+ ### Bug fixes
4
+
5
+ Give lint action buttons a pointer cursor style.
6
+
7
+ Fix a bug that caused diagnostic action callbacks to be called twice when their button was clicked.
8
+
9
+ ## 6.1.0 (2022-11-15)
10
+
11
+ ### New features
12
+
13
+ The new `forEachDiagnostic` function can be used to iterate over the diagnostics in an editor state.
14
+
1
15
  ## 6.0.0 (2022-06-08)
2
16
 
3
17
  ### Breaking changes
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (C) 2018-2021 by Marijn Haverbeke <marijnh@gmail.com> and others
3
+ Copyright (C) 2018-2021 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # @codemirror/lint [![NPM version](https://img.shields.io/npm/v/@codemirror/lint.svg)](https://www.npmjs.org/package/@codemirror/lint)
2
2
 
3
- [ [**WEBSITE**](https://codemirror.net/6/) | [**DOCS**](https://codemirror.net/6/docs/ref/#lint) | [**ISSUES**](https://github.com/codemirror/codemirror.next/issues) | [**FORUM**](https://discuss.codemirror.net/c/next/) | [**CHANGELOG**](https://github.com/codemirror/lint/blob/main/CHANGELOG.md) ]
3
+ [ [**WEBSITE**](https://codemirror.net/) | [**DOCS**](https://codemirror.net/docs/ref/#lint) | [**ISSUES**](https://github.com/codemirror/dev/issues) | [**FORUM**](https://discuss.codemirror.net/c/next/) | [**CHANGELOG**](https://github.com/codemirror/lint/blob/main/CHANGELOG.md) ]
4
4
 
5
5
  This package implements linting support for the
6
- [CodeMirror](https://codemirror.net/6/) code editor.
6
+ [CodeMirror](https://codemirror.net/) code editor.
7
7
 
8
- The [project page](https://codemirror.net/6/) has more information, a
9
- number of [examples](https://codemirror.net/6/examples/) and the
10
- [documentation](https://codemirror.net/6/docs/).
8
+ The [project page](https://codemirror.net/) has more information, a
9
+ number of [examples](https://codemirror.net/examples/) and the
10
+ [documentation](https://codemirror.net/docs/).
11
11
 
12
12
  This code is released under an
13
13
  [MIT license](https://github.com/codemirror/lint/tree/main/LICENSE).
package/dist/index.cjs CHANGED
@@ -197,7 +197,7 @@ A set of default key bindings for the lint functionality.
197
197
  - F8: [`nextDiagnostic`](https://codemirror.net/6/docs/ref/#lint.nextDiagnostic)
198
198
  */
199
199
  const lintKeymap = [
200
- { key: "Mod-Shift-m", run: openLintPanel },
200
+ { key: "Mod-Shift-m", run: openLintPanel, preventDefault: true },
201
201
  { key: "F8", run: nextDiagnostic }
202
202
  ];
203
203
  const lintPlugin = view.ViewPlugin.fromClass(class {
@@ -291,8 +291,11 @@ function renderDiagnostic(view, diagnostic, inPanel) {
291
291
  var _a;
292
292
  let keys = inPanel ? assignKeys(diagnostic.actions) : [];
293
293
  return elt__default["default"]("li", { class: "cm-diagnostic cm-diagnostic-" + diagnostic.severity }, elt__default["default"]("span", { class: "cm-diagnosticText" }, diagnostic.renderMessage ? diagnostic.renderMessage() : diagnostic.message), (_a = diagnostic.actions) === null || _a === void 0 ? void 0 : _a.map((action, i) => {
294
- let click = (e) => {
294
+ let fired = false, click = (e) => {
295
295
  e.preventDefault();
296
+ if (fired)
297
+ return;
298
+ fired = true;
296
299
  let found = findDiagnostic(view.state.field(lintState).diagnostics, diagnostic);
297
300
  if (found)
298
301
  action.apply(view, found.from, found.to);
@@ -519,7 +522,8 @@ const baseTheme = view.EditorView.baseTheme({
519
522
  backgroundColor: "#444",
520
523
  color: "white",
521
524
  borderRadius: "3px",
522
- marginLeft: "8px"
525
+ marginLeft: "8px",
526
+ cursor: "pointer"
523
527
  },
524
528
  ".cm-diagnosticSource": {
525
529
  fontSize: "70%",
@@ -611,8 +615,8 @@ class LintGutterMarker extends view.GutterMarker {
611
615
  function trackHoverOn(view, marker) {
612
616
  let mousemove = (event) => {
613
617
  let rect = marker.getBoundingClientRect();
614
- if (event.clientX > rect.left - 10 /* Margin */ && event.clientX < rect.right + 10 /* Margin */ &&
615
- event.clientY > rect.top - 10 /* Margin */ && event.clientY < rect.bottom + 10 /* Margin */)
618
+ if (event.clientX > rect.left - 10 /* Hover.Margin */ && event.clientX < rect.right + 10 /* Hover.Margin */ &&
619
+ event.clientY > rect.top - 10 /* Hover.Margin */ && event.clientY < rect.bottom + 10 /* Hover.Margin */)
616
620
  return;
617
621
  for (let target = event.target; target; target = target.parentNode) {
618
622
  if (target.nodeType == 1 && target.classList.contains("cm-tooltip-lint"))
@@ -715,14 +719,14 @@ const lintGutterTheme = view.EditorView.baseTheme({
715
719
  ".cm-lint-marker-warning": {
716
720
  content: svg(`<path fill="#fe8" stroke="#fd7" stroke-width="6" stroke-linejoin="round" d="M20 6L37 35L3 35Z"/>`),
717
721
  },
718
- ".cm-lint-marker-error:before": {
722
+ ".cm-lint-marker-error": {
719
723
  content: svg(`<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>`)
720
724
  },
721
725
  });
722
726
  const lintGutterConfig = state.Facet.define({
723
727
  combine(configs) {
724
728
  return state.combineConfig(configs, {
725
- hoverTime: 300 /* Time */,
729
+ hoverTime: 300 /* Hover.Time */,
726
730
  markerFilter: null,
727
731
  tooltipFilter: null
728
732
  });
@@ -736,9 +740,23 @@ the diagnostics.
736
740
  function lintGutter(config = {}) {
737
741
  return [lintGutterConfig.of(config), lintGutterMarkers, lintGutterExtension, lintGutterTheme, lintGutterTooltip];
738
742
  }
743
+ /**
744
+ Iterate over the marked diagnostics for the given editor state,
745
+ calling `f` for each of them. Note that, if the document changed
746
+ since the diagnostics were created, the `Diagnostic` object will
747
+ hold the original outdated position, whereas the `to` and `from`
748
+ arguments hold the diagnostic's current position.
749
+ */
750
+ function forEachDiagnostic(state$1, f) {
751
+ let lState = state$1.field(lintState, false);
752
+ if (lState && lState.diagnostics.size)
753
+ for (let iter = state.RangeSet.iter([lState.diagnostics]); iter.value; iter.next())
754
+ f(iter.value.spec.diagnostic, iter.from, iter.to);
755
+ }
739
756
 
740
757
  exports.closeLintPanel = closeLintPanel;
741
758
  exports.diagnosticCount = diagnosticCount;
759
+ exports.forEachDiagnostic = forEachDiagnostic;
742
760
  exports.forceLinting = forceLinting;
743
761
  exports.lintGutter = lintGutter;
744
762
  exports.lintKeymap = lintKeymap;
package/dist/index.d.ts CHANGED
@@ -145,5 +145,13 @@ each line that has diagnostics, which can be hovered over to see
145
145
  the diagnostics.
146
146
  */
147
147
  declare function lintGutter(config?: LintGutterConfig): Extension;
148
+ /**
149
+ Iterate over the marked diagnostics for the given editor state,
150
+ calling `f` for each of them. Note that, if the document changed
151
+ since the diagnostics were created, the `Diagnostic` object will
152
+ hold the original outdated position, whereas the `to` and `from`
153
+ arguments hold the diagnostic's current position.
154
+ */
155
+ declare function forEachDiagnostic(state: EditorState, f: (d: Diagnostic, from: number, to: number) => void): void;
148
156
 
149
- export { Action, Diagnostic, LintSource, closeLintPanel, diagnosticCount, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, setDiagnostics, setDiagnosticsEffect };
157
+ export { Action, Diagnostic, LintSource, closeLintPanel, diagnosticCount, forEachDiagnostic, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, setDiagnostics, setDiagnosticsEffect };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Decoration, showPanel, EditorView, ViewPlugin, hoverTooltip, logException, gutter, showTooltip, getPanel, WidgetType, GutterMarker } from '@codemirror/view';
1
+ import { Decoration, showPanel, EditorView, ViewPlugin, logException, gutter, showTooltip, getPanel, WidgetType, hoverTooltip, GutterMarker } from '@codemirror/view';
2
2
  import { StateEffect, StateField, Facet, combineConfig, RangeSet } from '@codemirror/state';
3
3
  import elt from 'crelt';
4
4
 
@@ -189,7 +189,7 @@ A set of default key bindings for the lint functionality.
189
189
  - F8: [`nextDiagnostic`](https://codemirror.net/6/docs/ref/#lint.nextDiagnostic)
190
190
  */
191
191
  const lintKeymap = [
192
- { key: "Mod-Shift-m", run: openLintPanel },
192
+ { key: "Mod-Shift-m", run: openLintPanel, preventDefault: true },
193
193
  { key: "F8", run: nextDiagnostic }
194
194
  ];
195
195
  const lintPlugin = /*@__PURE__*/ViewPlugin.fromClass(class {
@@ -283,8 +283,11 @@ function renderDiagnostic(view, diagnostic, inPanel) {
283
283
  var _a;
284
284
  let keys = inPanel ? assignKeys(diagnostic.actions) : [];
285
285
  return elt("li", { class: "cm-diagnostic cm-diagnostic-" + diagnostic.severity }, elt("span", { class: "cm-diagnosticText" }, diagnostic.renderMessage ? diagnostic.renderMessage() : diagnostic.message), (_a = diagnostic.actions) === null || _a === void 0 ? void 0 : _a.map((action, i) => {
286
- let click = (e) => {
286
+ let fired = false, click = (e) => {
287
287
  e.preventDefault();
288
+ if (fired)
289
+ return;
290
+ fired = true;
288
291
  let found = findDiagnostic(view.state.field(lintState).diagnostics, diagnostic);
289
292
  if (found)
290
293
  action.apply(view, found.from, found.to);
@@ -511,7 +514,8 @@ const baseTheme = /*@__PURE__*/EditorView.baseTheme({
511
514
  backgroundColor: "#444",
512
515
  color: "white",
513
516
  borderRadius: "3px",
514
- marginLeft: "8px"
517
+ marginLeft: "8px",
518
+ cursor: "pointer"
515
519
  },
516
520
  ".cm-diagnosticSource": {
517
521
  fontSize: "70%",
@@ -603,8 +607,8 @@ class LintGutterMarker extends GutterMarker {
603
607
  function trackHoverOn(view, marker) {
604
608
  let mousemove = (event) => {
605
609
  let rect = marker.getBoundingClientRect();
606
- if (event.clientX > rect.left - 10 /* Margin */ && event.clientX < rect.right + 10 /* Margin */ &&
607
- event.clientY > rect.top - 10 /* Margin */ && event.clientY < rect.bottom + 10 /* Margin */)
610
+ if (event.clientX > rect.left - 10 /* Hover.Margin */ && event.clientX < rect.right + 10 /* Hover.Margin */ &&
611
+ event.clientY > rect.top - 10 /* Hover.Margin */ && event.clientY < rect.bottom + 10 /* Hover.Margin */)
608
612
  return;
609
613
  for (let target = event.target; target; target = target.parentNode) {
610
614
  if (target.nodeType == 1 && target.classList.contains("cm-tooltip-lint"))
@@ -707,14 +711,14 @@ const lintGutterTheme = /*@__PURE__*/EditorView.baseTheme({
707
711
  ".cm-lint-marker-warning": {
708
712
  content: /*@__PURE__*/svg(`<path fill="#fe8" stroke="#fd7" stroke-width="6" stroke-linejoin="round" d="M20 6L37 35L3 35Z"/>`),
709
713
  },
710
- ".cm-lint-marker-error:before": {
714
+ ".cm-lint-marker-error": {
711
715
  content: /*@__PURE__*/svg(`<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>`)
712
716
  },
713
717
  });
714
718
  const lintGutterConfig = /*@__PURE__*/Facet.define({
715
719
  combine(configs) {
716
720
  return combineConfig(configs, {
717
- hoverTime: 300 /* Time */,
721
+ hoverTime: 300 /* Hover.Time */,
718
722
  markerFilter: null,
719
723
  tooltipFilter: null
720
724
  });
@@ -728,5 +732,18 @@ the diagnostics.
728
732
  function lintGutter(config = {}) {
729
733
  return [lintGutterConfig.of(config), lintGutterMarkers, lintGutterExtension, lintGutterTheme, lintGutterTooltip];
730
734
  }
735
+ /**
736
+ Iterate over the marked diagnostics for the given editor state,
737
+ calling `f` for each of them. Note that, if the document changed
738
+ since the diagnostics were created, the `Diagnostic` object will
739
+ hold the original outdated position, whereas the `to` and `from`
740
+ arguments hold the diagnostic's current position.
741
+ */
742
+ function forEachDiagnostic(state, f) {
743
+ let lState = state.field(lintState, false);
744
+ if (lState && lState.diagnostics.size)
745
+ for (let iter = RangeSet.iter([lState.diagnostics]); iter.value; iter.next())
746
+ f(iter.value.spec.diagnostic, iter.from, iter.to);
747
+ }
731
748
 
732
- export { closeLintPanel, diagnosticCount, forceLinting, lintGutter, lintKeymap, linter, nextDiagnostic, openLintPanel, setDiagnostics, setDiagnosticsEffect };
749
+ export { closeLintPanel, diagnosticCount, forEachDiagnostic, 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": "6.0.0",
3
+ "version": "6.1.1",
4
4
  "description": "Linting support for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",
@@ -12,7 +12,7 @@
12
12
  ],
13
13
  "author": {
14
14
  "name": "Marijn Haverbeke",
15
- "email": "marijnh@gmail.com",
15
+ "email": "marijn@haverbeke.berlin",
16
16
  "url": "http://marijnhaverbeke.nl"
17
17
  },
18
18
  "type": "module",