Skip to content

Commit 5a8fd85

Browse files
committed
fix: highlighting mode doesn't scroll the preview to select element
1 parent c1a335e commit 5a8fd85

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,9 @@ function RemoteFunctions(config = {}) {
918918

919919
const nodes = window.document.querySelectorAll(rule);
920920

921-
// Highlight all matching nodes
921+
// Highlight all matching nodes. selectElement() will narrow _clickHighlight
922+
// down to the chosen element below; createCssSelectorHighlight() then
923+
// re-highlights the siblings in a separate overlay.
922924
for (let i = 0; i < nodes.length; i++) {
923925
highlight(nodes[i]);
924926
}
@@ -927,22 +929,23 @@ function RemoteFunctions(config = {}) {
927929
_clickHighlight.selector = rule;
928930
}
929931

930-
// In edit mode, select the best element and create temporary highlights for the rest.
931-
// In highlight mode, skip selection so all matching elements stay highlighted equally.
932-
if (config.mode === 'edit') {
933-
const { element, skipSelection } = findBestElementToSelect(nodes, rule);
934-
935-
if (!skipSelection) {
936-
if (element) {
937-
selectElement(element, true);
938-
} else {
939-
// No valid element found, dismiss UI
940-
dismissUIAndCleanupState();
941-
}
942-
}
932+
// Both edit and highlight modes go through the same selection path:
933+
// selectElement() handles scroll-to-view and the prominent click-highlight,
934+
// createCssSelectorHighlight() shows siblings dimly. fromEditor=true
935+
// suppresses tool-handler invocation, so highlight mode gets the
936+
// highlighting/scroll behavior without any UI boxes.
937+
const { element, skipSelection } = findBestElementToSelect(nodes, rule);
943938

944-
createCssSelectorHighlight(nodes, rule);
939+
if (!skipSelection) {
940+
if (element) {
941+
selectElement(element, true);
942+
} else {
943+
// No valid element found, dismiss UI
944+
dismissUIAndCleanupState();
945+
}
945946
}
947+
948+
createCssSelectorHighlight(nodes, rule);
946949
}
947950

948951
// recreate UI boxes so that they are placed properly

0 commit comments

Comments
 (0)