Skip to content

Commit c89fb78

Browse files
committed
fix: element highlighting improvements for better multi selection support
1 parent 61dc2ee commit c89fb78

2 files changed

Lines changed: 29 additions & 12 deletions

File tree

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,13 @@ function RemoteFunctions(config = {}) {
11301130
if (previouslySelectedElement && !previouslySelectedElement.isConnected) {
11311131
dismissUIAndCleanupState();
11321132
} else {
1133+
// Re-apply outline since attrChange may have wiped it
1134+
// (e.g. user edited the style attribute in source)
1135+
if (previouslySelectedElement && previouslySelectedElement.isConnected) {
1136+
const isEditable = previouslySelectedElement.hasAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR);
1137+
const outlineColor = isEditable ? COLORS.outlineEditable : COLORS.outlineNonEditable;
1138+
previouslySelectedElement.style.outline = `1px solid ${outlineColor}`;
1139+
}
11331140
redrawEverything();
11341141
}
11351142
} else {
@@ -1432,7 +1439,7 @@ function RemoteFunctions(config = {}) {
14321439
customReturns = { // we have to do this else the minifier will strip the customReturns variable
14331440
...customReturns,
14341441
"DOMEditHandler": DOMEditHandler,
1435-
"hideHighlight": hideHighlight,
1442+
"hideHighlight": dismissUIAndCleanupState,
14361443
"highlight": highlight,
14371444
"highlightRule": highlightRule,
14381445
"redrawHighlights": redrawHighlights,

src/LiveDevelopment/MultiBrowserImpl/documents/LiveHTMLDocument.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ define(function (require, exports, module) {
3434
_ = require("thirdparty/lodash"),
3535
LiveDocument = require("LiveDevelopment/MultiBrowserImpl/documents/LiveDocument"),
3636
HTMLInstrumentation = require("LiveDevelopment/MultiBrowserImpl/language/HTMLInstrumentation"),
37+
HTMLUtils = require("language/HTMLUtils"),
3738
CSSUtils = require("language/CSSUtils");
3839

3940
/**
@@ -161,19 +162,28 @@ define(function (require, exports, module) {
161162
selectors = [];
162163

163164
// check if the cursor is in a stylesheet context (internal styles)
165+
// but skip CSS selector lookup for inline style attributes (style="...")
166+
// since they have no selector — the element itself should be highlighted instead
164167
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-
});
168+
var primarySel = editor.getSelection();
169+
var tagInfo = HTMLUtils.getTagInfo(editor, primarySel.start, true);
170+
var isInlineStyle = tagInfo.position.tokenType === HTMLUtils.ATTR_VALUE &&
171+
tagInfo.attr.name.toLowerCase() === "style";
172+
173+
if (!isInlineStyle) {
174+
// find the css selector
175+
_.each(this.editor.getSelections(), function (sel) {
176+
let selector = CSSUtils.findSelectorAtDocumentPos(editor, (sel.reversed ? sel.end : sel.start));
177+
if (selector) {
178+
selectors.push(selector);
179+
}
180+
});
172181

173-
if (selectors.length) {
174-
// to highlight the elements that match the css selectors
175-
this.highlightRule(selectors.join(","));
176-
return;
182+
if (selectors.length) {
183+
// to highlight the elements that match the css selectors
184+
this.highlightRule(selectors.join(","));
185+
return;
186+
}
177187
}
178188
}
179189

0 commit comments

Comments
 (0)