@@ -268,6 +268,7 @@ function RemoteFunctions(config = {}) {
268268 selectElement : selectElement ,
269269 isSelectedFromEditor : function ( ) { return _selectedFromEditor ; } ,
270270 highlightRuleAroundSelection : highlightRuleAroundSelection ,
271+ getCaretTarget : function ( ) { return _caretTarget ; } ,
271272 isNamedSelection : _isNamedSelection ,
272273 toMatchableSelector : toMatchableSelector ,
273274 sendSelectionToEditor : sendSelectionToEditor ,
@@ -516,9 +517,8 @@ function RemoteFunctions(config = {}) {
516517 return measured ;
517518 }
518519
519- // Margin and padding fills belong to the selected element, picked in the page or by the
520- // caret in its code, and to the element the caret points at beside a held selection.
521- // A hover and the other matches of a css rule only get the outline.
520+ // Margin and padding fills belong to the selected element and to the one the caret
521+ // points at. A hover and the other matches of a css rule only get the outline.
522522 function _showsBoxModel ( element , outlineOnly ) {
523523 return ! outlineOnly && ( element === previouslySelectedElement || element === _caretTarget ) &&
524524 ! SHARED_STATE . _boxModelHighlightHidden ;
@@ -1257,17 +1257,23 @@ function RemoteFunctions(config = {}) {
12571257 return toMatchableSelector ( rule ) . split ( "," ) . map ( s => s . trim ( ) ) . filter ( s => s !== "*" ) . join ( "," ) ;
12581258 }
12591259
1260+ // only a pick is held, not a selection the caret made before anything held it
1261+ function _dropCaretMadeSelection ( ) {
1262+ if ( previouslySelectedElement && _selectedFromEditor ) {
1263+ dismissUIAndCleanupState ( ) ;
1264+ }
1265+ }
1266+
12601267 /**
1261- * The caret highlight while something else holds the selection (a layers panel pick).
1262- * What the rule reaches is outlined and scrolled into view the same as when the caret
1263- * selects, but the held element keeps the selection and its tools.
1268+ * Highlight and scroll to what the rule reaches without selecting it: the selection
1269+ * is held elsewhere (the layers panel) and a picked element keeps it.
12641270 * @param {string } rule - The CSS rule to highlight
1265- * @returns {Element|null } the element the caret is taken to point at, null when the
1266- * rule reaches nothing or reaches the held element itself
1271+ * @returns {Element|null } the element the caret points at, null when it is the held one
12671272 */
12681273 function highlightRuleAroundSelection ( rule ) {
1274+ _dropCaretMadeSelection ( ) ;
12691275 rule = _withoutUniversalSelector ( rule ) ;
1270- // the live document and a panel reading the same caret both ask, the second for what is drawn
1276+ // already drawn: the live document and the layers panel both ask for the same caret
12711277 if ( rule && _cssSelectorHighlight && _cssSelectorHighlight . selector === rule ) {
12721278 return _caretTarget ;
12731279 }
@@ -1281,8 +1287,8 @@ function RemoteFunctions(config = {}) {
12811287 if ( element ) {
12821288 scrollElementToViewPort ( element ) ;
12831289 }
1284- // set before drawing: the overlay paints its margin and padding by it
1285- _caretTarget = element && element !== previouslySelectedElement ? element : null ;
1290+ // set before drawing, the overlay paints margin and padding by it
1291+ _caretTarget = element && element !== previouslySelectedElement ? element : null ;
12861292 createCssSelectorHighlight ( nodes , rule ) ;
12871293 return _caretTarget ;
12881294 }
@@ -1973,13 +1979,10 @@ function RemoteFunctions(config = {}) {
19731979 cleanupPreviousElementState ( ) ;
19741980 }
19751981
1976- /**
1977- * The editor caret left everything it could highlight. That drops the selection too,
1978- * unless it is held elsewhere: then only what the caret pointed at goes.
1979- * @param {boolean } [keepSelection]
1980- */
1982+ // The editor has nothing to highlight. A selection held elsewhere stays.
19811983 function hideEditorHighlight ( keepSelection ) {
19821984 if ( keepSelection ) {
1985+ _dropCaretMadeSelection ( ) ;
19831986 _caretTarget = null ;
19841987 clearCssSelectorHighlight ( ) ;
19851988 return ;
0 commit comments