[lint addon] Use separate CSS classes for common lint styles

This changes lint.css to be less reliant on the predefined severities
(error and warning), in turn making it easier to define custom ones.
Now all that needs to be done in order to define a new severity, e.g.
`note`, is to add the following CSS:

```css
/* underline */
.CodeMirror-lint-mark-note {
  background-image: ...;
}

/* icon */
.CodeMirror-lint-marker-note, .CodeMirror-lint-message-note {
  background-image: ...;
}
```

Previously, it was necessary to copy many styles that were only
available under the `CodeMirror-lint-*-error` and
`CodeMirror-lint-*-warning` classes.
This commit is contained in:
Adrian Kunz 2020-09-17 11:32:20 +02:00 committed by Marijn Haverbeke
parent db719a2e37
commit 18aa69e17c
2 changed files with 7 additions and 7 deletions

View File

@ -25,7 +25,7 @@
-ms-transition: opacity .4s; -ms-transition: opacity .4s;
} }
.CodeMirror-lint-mark-error, .CodeMirror-lint-mark-warning { .CodeMirror-lint-mark {
background-position: left bottom; background-position: left bottom;
background-repeat: repeat-x; background-repeat: repeat-x;
} }
@ -40,7 +40,7 @@
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJFhQXEbhTg7YAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAMklEQVQI12NkgIIvJ3QXMjAwdDN+OaEbysDA4MPAwNDNwMCwiOHLCd1zX07o6kBVGQEAKBANtobskNMAAAAASUVORK5CYII="); background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAADCAYAAAC09K7GAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sJFhQXEbhTg7YAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAMklEQVQI12NkgIIvJ3QXMjAwdDN+OaEbysDA4MPAwNDNwMCwiOHLCd1zX07o6kBVGQEAKBANtobskNMAAAAASUVORK5CYII=");
} }
.CodeMirror-lint-marker-error, .CodeMirror-lint-marker-warning { .CodeMirror-lint-marker {
background-position: center center; background-position: center center;
background-repeat: no-repeat; background-repeat: no-repeat;
cursor: pointer; cursor: pointer;
@ -51,7 +51,7 @@
position: relative; position: relative;
} }
.CodeMirror-lint-message-error, .CodeMirror-lint-message-warning { .CodeMirror-lint-message {
padding-left: 18px; padding-left: 18px;
background-position: top left; background-position: top left;
background-repeat: no-repeat; background-repeat: no-repeat;

View File

@ -83,10 +83,10 @@
function makeMarker(cm, labels, severity, multiple, tooltips) { function makeMarker(cm, labels, severity, multiple, tooltips) {
var marker = document.createElement("div"), inner = marker; var marker = document.createElement("div"), inner = marker;
marker.className = "CodeMirror-lint-marker-" + severity; marker.className = "CodeMirror-lint-marker CodeMirror-lint-marker-" + severity;
if (multiple) { if (multiple) {
inner = marker.appendChild(document.createElement("div")); inner = marker.appendChild(document.createElement("div"));
inner.className = "CodeMirror-lint-marker-multiple"; inner.className = "CodeMirror-lint-marker CodeMirror-lint-marker-multiple";
} }
if (tooltips != false) CodeMirror.on(inner, "mouseover", function(e) { if (tooltips != false) CodeMirror.on(inner, "mouseover", function(e) {
@ -114,7 +114,7 @@
var severity = ann.severity; var severity = ann.severity;
if (!severity) severity = "error"; if (!severity) severity = "error";
var tip = document.createElement("div"); var tip = document.createElement("div");
tip.className = "CodeMirror-lint-message-" + severity; tip.className = "CodeMirror-lint-message CodeMirror-lint-message-" + severity;
if (typeof ann.messageHTML != 'undefined') { if (typeof ann.messageHTML != 'undefined') {
tip.innerHTML = ann.messageHTML; tip.innerHTML = ann.messageHTML;
} else { } else {
@ -183,7 +183,7 @@
if (state.hasGutter) tipLabel.appendChild(annotationTooltip(ann)); if (state.hasGutter) tipLabel.appendChild(annotationTooltip(ann));
if (ann.to) state.marked.push(cm.markText(ann.from, ann.to, { if (ann.to) state.marked.push(cm.markText(ann.from, ann.to, {
className: "CodeMirror-lint-mark-" + severity, className: "CodeMirror-lint-mark CodeMirror-lint-mark-" + severity,
__annotation: ann __annotation: ann
})); }));
} }