Skip to content

Commit aa62f90

Browse files
committed
fix: element highlighting not working for internal stylesheet
1 parent 92ea205 commit aa62f90

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

src/LiveDevelopment/MultiBrowserImpl/documents/LiveHTMLDocument.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ define(function (require, exports, module) {
3333
PerfUtils = require("utils/PerfUtils"),
3434
_ = require("thirdparty/lodash"),
3535
LiveDocument = require("LiveDevelopment/MultiBrowserImpl/documents/LiveDocument"),
36-
HTMLInstrumentation = require("LiveDevelopment/MultiBrowserImpl/language/HTMLInstrumentation");
37-
36+
HTMLInstrumentation = require("LiveDevelopment/MultiBrowserImpl/language/HTMLInstrumentation"),
37+
CSSUtils = require("language/CSSUtils");
3838

3939
/**
4040
* @constructor
@@ -156,7 +156,28 @@ define(function (require, exports, module) {
156156
return;
157157
}
158158
var editor = this.editor,
159-
ids = [];
159+
mode = editor.getModeForSelection(),
160+
ids = [],
161+
selectors = [];
162+
163+
// check if the cursor is in a stylesheet context (internal styles)
164+
if (mode === "css" || mode === "text/x-scss" || mode === "text/x-less") {
165+
// find the css selector
166+
_.each(this.editor.getSelections(), function (sel) {
167+
let selector = CSSUtils.findSelectorAtDocumentPos(editor, (sel.reversed ? sel.end : sel.start));
168+
if (selector) {
169+
selectors.push(selector);
170+
}
171+
});
172+
173+
if (selectors.length) {
174+
// to highlight the elements that match the css selectors
175+
this.highlightRule(selectors.join(","));
176+
return;
177+
}
178+
}
179+
180+
// its not found in css context, then it must be a inline style or a normal html element
160181
_.each(this.editor.getSelections(), function (sel) {
161182
var tagID = HTMLInstrumentation._getTagIDAtDocumentPos(
162183
editor,

0 commit comments

Comments
 (0)