@codemirror/lint 6.7.1 → 6.8.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 6.8.1 (2024-06-19)
2
+
3
+ ### Bug fixes
4
+
5
+ Make lint markers non-inclusive again, since having them that way causes more issues than it solves.
6
+
7
+ ## 6.8.0 (2024-05-23)
8
+
9
+ ### New features
10
+
11
+ The new `autoPanel` option can be used to make the panel automatically appear when diagnostics are added and close when no diagnostics are left.
12
+
1
13
  ## 6.7.1 (2024-05-15)
2
14
 
3
15
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -32,8 +32,7 @@ class LintState {
32
32
  }).range(d.from)
33
33
  : view.Decoration.mark({
34
34
  attributes: { class: "cm-lintRange cm-lintRange-" + d.severity + (d.markClass ? " " + d.markClass : "") },
35
- diagnostic: d,
36
- inclusive: true
35
+ diagnostic: d
37
36
  }).range(d.from, d.to);
38
37
  }), true);
39
38
  return new LintState(ranges, panel, findDiagnostic(ranges));
@@ -82,17 +81,20 @@ const lintState = state.StateField.define({
82
81
  return new LintState(view.Decoration.none, null, null);
83
82
  },
84
83
  update(value, tr) {
85
- if (tr.docChanged) {
86
- let mapped = value.diagnostics.map(tr.changes), selected = null;
84
+ if (tr.docChanged && value.diagnostics.size) {
85
+ let mapped = value.diagnostics.map(tr.changes), selected = null, panel = value.panel;
87
86
  if (value.selected) {
88
87
  let selPos = tr.changes.mapPos(value.selected.from, 1);
89
88
  selected = findDiagnostic(mapped, value.selected.diagnostic, selPos) || findDiagnostic(mapped, null, selPos);
90
89
  }
91
- value = new LintState(mapped, value.panel, selected);
90
+ if (!mapped.size && panel && tr.state.facet(lintConfig).autoPanel)
91
+ panel = null;
92
+ value = new LintState(mapped, panel, selected);
92
93
  }
93
94
  for (let effect of tr.effects) {
94
95
  if (effect.is(setDiagnosticsEffect)) {
95
- value = LintState.init(effect.value, value.panel, tr.state);
96
+ let panel = !tr.state.facet(lintConfig).autoPanel ? value.panel : effect.value.length ? LintPanel.open : null;
97
+ value = LintState.init(effect.value, panel, tr.state);
96
98
  }
97
99
  else if (effect.is(togglePanel)) {
98
100
  value = new LintState(value.diagnostics, effect.value ? LintPanel.open : null, value.selected);
@@ -113,7 +115,7 @@ function diagnosticCount(state) {
113
115
  let lint = state.field(lintState, false);
114
116
  return lint ? lint.diagnostics.size : 0;
115
117
  }
116
- const activeMark = view.Decoration.mark({ class: "cm-lintRange cm-lintRange-active", inclusive: true });
118
+ const activeMark = view.Decoration.mark({ class: "cm-lintRange cm-lintRange-active" });
117
119
  function lintTooltip(view, pos, side) {
118
120
  let { diagnostics } = view.state.field(lintState);
119
121
  let found = [], stackStart = 2e8, stackEnd = 0;
package/dist/index.d.cts CHANGED
@@ -93,6 +93,12 @@ interface LintConfig {
93
93
  behavior.
94
94
  */
95
95
  hideOn?: (tr: Transaction, from: number, to: number) => boolean | null;
96
+ /**
97
+ When enabled (defaults to off), this will cause the lint panel
98
+ to automatically open when diagnostics are found, and close when
99
+ all diagnostics are resolved or removed.
100
+ */
101
+ autoPanel?: boolean;
96
102
  }
97
103
  interface LintGutterConfig {
98
104
  /**
package/dist/index.d.ts CHANGED
@@ -93,6 +93,12 @@ interface LintConfig {
93
93
  behavior.
94
94
  */
95
95
  hideOn?: (tr: Transaction, from: number, to: number) => boolean | null;
96
+ /**
97
+ When enabled (defaults to off), this will cause the lint panel
98
+ to automatically open when diagnostics are found, and close when
99
+ all diagnostics are resolved or removed.
100
+ */
101
+ autoPanel?: boolean;
96
102
  }
97
103
  interface LintGutterConfig {
98
104
  /**
package/dist/index.js CHANGED
@@ -30,8 +30,7 @@ class LintState {
30
30
  }).range(d.from)
31
31
  : Decoration.mark({
32
32
  attributes: { class: "cm-lintRange cm-lintRange-" + d.severity + (d.markClass ? " " + d.markClass : "") },
33
- diagnostic: d,
34
- inclusive: true
33
+ diagnostic: d
35
34
  }).range(d.from, d.to);
36
35
  }), true);
37
36
  return new LintState(ranges, panel, findDiagnostic(ranges));
@@ -80,17 +79,20 @@ const lintState = /*@__PURE__*/StateField.define({
80
79
  return new LintState(Decoration.none, null, null);
81
80
  },
82
81
  update(value, tr) {
83
- if (tr.docChanged) {
84
- let mapped = value.diagnostics.map(tr.changes), selected = null;
82
+ if (tr.docChanged && value.diagnostics.size) {
83
+ let mapped = value.diagnostics.map(tr.changes), selected = null, panel = value.panel;
85
84
  if (value.selected) {
86
85
  let selPos = tr.changes.mapPos(value.selected.from, 1);
87
86
  selected = findDiagnostic(mapped, value.selected.diagnostic, selPos) || findDiagnostic(mapped, null, selPos);
88
87
  }
89
- value = new LintState(mapped, value.panel, selected);
88
+ if (!mapped.size && panel && tr.state.facet(lintConfig).autoPanel)
89
+ panel = null;
90
+ value = new LintState(mapped, panel, selected);
90
91
  }
91
92
  for (let effect of tr.effects) {
92
93
  if (effect.is(setDiagnosticsEffect)) {
93
- value = LintState.init(effect.value, value.panel, tr.state);
94
+ let panel = !tr.state.facet(lintConfig).autoPanel ? value.panel : effect.value.length ? LintPanel.open : null;
95
+ value = LintState.init(effect.value, panel, tr.state);
94
96
  }
95
97
  else if (effect.is(togglePanel)) {
96
98
  value = new LintState(value.diagnostics, effect.value ? LintPanel.open : null, value.selected);
@@ -111,7 +113,7 @@ function diagnosticCount(state) {
111
113
  let lint = state.field(lintState, false);
112
114
  return lint ? lint.diagnostics.size : 0;
113
115
  }
114
- const activeMark = /*@__PURE__*/Decoration.mark({ class: "cm-lintRange cm-lintRange-active", inclusive: true });
116
+ const activeMark = /*@__PURE__*/Decoration.mark({ class: "cm-lintRange cm-lintRange-active" });
115
117
  function lintTooltip(view, pos, side) {
116
118
  let { diagnostics } = view.state.field(lintState);
117
119
  let found = [], stackStart = 2e8, stackEnd = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/lint",
3
- "version": "6.7.1",
3
+ "version": "6.8.1",
4
4
  "description": "Linting support for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",