Skip to content

Commit 3f863f7

Browse files
committed
feat: svg color gutter previews
1 parent 6c95208 commit 3f863f7

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

docs/API-Reference/editor/Editor.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const Editor = brackets.getModule("editor/Editor")
5959
* [.getMarksAfter(position, markType)](#Editor+getMarksAfter) ⇒ <code>Array.&lt;TextMarker&gt;</code>
6060
* [.getMarksBefore(position, markType)](#Editor+getMarksBefore) ⇒ <code>Array.&lt;TextMarker&gt;</code>
6161
* [.getAllMarks([markType])](#Editor+getAllMarks) ⇒ <code>Array.&lt;TextMarker&gt;</code>
62-
* [.clearAllMarks([markType])](#Editor+clearAllMarks)
62+
* [.clearAllMarks([markType], [lineNumbers])](#Editor+clearAllMarks)
6363
* [.isSamePosition(position1, position2)](#Editor+isSamePosition) ⇒ <code>boolean</code>
6464
* [.getHistory()](#Editor+getHistory) ⇒ <code>Array</code>
6565
* [.setHistory()](#Editor+setHistory)
@@ -729,14 +729,16 @@ Returns an array containing all marked ranges in the document.
729729

730730
<a name="Editor+clearAllMarks"></a>
731731

732-
### editor.clearAllMarks([markType])
733-
Clears all mark of the given type. If nothing is given, clears all marks(Don't use this API without types!).
732+
### editor.clearAllMarks([markType], [lineNumbers])
733+
Clears all marks of the given type. If a lineNumbers array is given, only clears marks on those lines.
734+
If no markType or lineNumbers are given, clears all marks (use cautiously).
734735

735736
**Kind**: instance method of [<code>Editor</code>](#Editor)
736737

737738
| Param | Type | Description |
738739
| --- | --- | --- |
739740
| [markType] | <code>string</code> | Optional, if given will only delete marks of that type. Else delete everything. |
741+
| [lineNumbers] | <code>Array.&lt;number&gt;</code> | Optional, array of line numbers where marks should be cleared. |
740742

741743
<a name="Editor+isSamePosition"></a>
742744

src/extensionsIntegrated/CSSColorPreview/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ define(function (require, exports, module) {
4848
COLOR_LANGUAGES= ["css", "scss", "less", "sass", "stylus", "html", "svg", "jsx", "tsx",
4949
"php", "ejs", "erb_html", "pug"];
5050

51+
const SVG_REGEX = /(:[^;]*;?|(?:fill|stroke|stop-color|flood-color|lighting-color|background-color|border-color|from|to)\s*=\s*(['"]?)[^'";]*\2)/g,
52+
CSS_REGEX = /:[^;]*;?/g; // the last semi colon is optional.
53+
5154

5255
// For preferences settings, to toggle this feature on/off
5356
const PREFERENCES_CSS_COLOR_PREVIEW = "colorPreview";
@@ -323,13 +326,14 @@ define(function (require, exports, module) {
323326
*/
324327
function detectValidColorsInLine(editor, lineNumber) {
325328
const lineText = editor.getLine(lineNumber);
329+
const languageID = editor.document.getLanguage().getId();
326330

327331
// to make sure that code doesn't break when lineText is null.
328332
if (!lineText) {
329333
return [];
330334
}
331335

332-
const valueRegex = /:[^;]*;?/g; // the last semi colon is optional.
336+
const valueRegex = languageID === "svg" ? SVG_REGEX: CSS_REGEX;
333337
const validColors = [];
334338

335339
// Find all property value sections in the line
Lines changed: 26 additions & 0 deletions
Loading

test/spec/Extn-CSSColorPreview-integ-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,5 +319,27 @@ define(function (require, exports, module) {
319319

320320
await __PR.closeFile();
321321
});
322+
323+
it(`should color gutter appear for SVG files`, async function () {
324+
await __PR.openFile("base.svg");
325+
const editor = EditorManager.getActiveEditor();
326+
__PR.validateEqual(editor.isGutterActive(GUTTER_NAME), true);
327+
328+
// the line with cursor if there is no color should have a dummy color gutter
329+
__PR.setCursors(["1:1"]);
330+
for(let i in [0, 2, 4, 5, 7, 8, 9, 11, 12, 13, 14, 17, 18, 19, 20]){
331+
validateNoColors(editor, i);
332+
}
333+
validateSingleColor(editor, 1, "#7f6ad3"); // fill attr
334+
validateMultipleColors(editor, 3, ["red", "blue"]); // from, to attrs
335+
validateMultipleColors(editor, 6, ["red", "#00ff00"]); // stroke attr
336+
validateSingleColor(editor, 10, "yellow"); // flood-color attr
337+
validateSingleColor(editor, 15, "coral"); // in css style tags
338+
validateSingleColor(editor, 16, "navy"); // in css style tag
339+
validateSingleColor(editor, 21, "red"); // stop-color attr
340+
validateSingleColor(editor, 22, "blue"); // stop-color attr
341+
await __PR.closeFile();
342+
343+
});
322344
});
323345
});

0 commit comments

Comments
 (0)