@@ -160,7 +160,9 @@ define(function (require, exports, module) {
160160 this . setInstrumentationEnabled ( true , true ) ;
161161 this . editor . off ( "cursorActivity" , this . _onCursorActivity ) ;
162162 this . editor . on ( "cursorActivity" , this . _onCursorActivity ) ;
163- this . updateHighlight ( ) ;
163+ if ( ! _isCursorHighlightGated ( this ) ) {
164+ this . updateHighlight ( ) ;
165+ }
164166 }
165167 } ;
166168
@@ -171,13 +173,29 @@ define(function (require, exports, module) {
171173 LiveDocument . prototype . _detachFromEditor = function ( ) {
172174 if ( this . editor ) {
173175 this . _cancelPendingHighlight ( ) ;
174- this . hideHighlight ( ) ;
176+ if ( ! _isCursorHighlightGated ( this ) ) {
177+ this . hideHighlight ( ) ;
178+ }
175179 this . editor . off ( "cursorActivity" , this . _onCursorActivity ) ;
176180 }
177181 } ;
178182
179183 let _disableHighlightOnCursor = false ;
180184 let _cursorHighlightGeneration = 0 ;
185+ let _cursorHighlightGate = null ;
186+
187+ /**
188+ * Lets something outside the live documents decide whether the caret may move
189+ * the preview highlight, such as a panel holding a selection of its own.
190+ * @param {?function(LiveDocument): boolean } gate Returns false to leave the preview alone; null removes it.
191+ */
192+ LiveDocument . setCursorHighlightGate = function ( gate ) {
193+ _cursorHighlightGate = gate || null ;
194+ } ;
195+
196+ function _isCursorHighlightGated ( liveDoc ) {
197+ return ! ! _cursorHighlightGate && _cursorHighlightGate ( liveDoc ) === false ;
198+ }
181199
182200 /**
183201 * If tur, it will disable highlights in live preview on cursor movement in editor
@@ -210,14 +228,15 @@ define(function (require, exports, module) {
210228 */
211229 LiveDocument . prototype . _onCursorActivity = function ( event , editor ) {
212230 this . _cancelPendingHighlight ( ) ;
213- if ( ! this . editor || _disableHighlightOnCursor ) {
231+ if ( ! this . editor || _disableHighlightOnCursor || _isCursorHighlightGated ( this ) ) {
214232 return ;
215233 }
216234 const self = this ;
217235 const generation = _cursorHighlightGeneration ;
218236 this . _highlightTimer = window . setTimeout ( function ( ) {
219237 self . _highlightTimer = null ;
220- if ( self . editor && ! _disableHighlightOnCursor && generation === _cursorHighlightGeneration ) {
238+ if ( self . editor && ! _disableHighlightOnCursor && generation === _cursorHighlightGeneration &&
239+ ! _isCursorHighlightGated ( self ) ) {
221240 self . updateHighlight ( ) ;
222241 }
223242 } , CURSOR_HIGHLIGHT_DEBOUNCE_MS ) ;
0 commit comments