Skip to content

Commit 8e151df

Browse files
devvaannshabose
authored andcommitted
feat: keep layers selection anchored on caret moves
1 parent fbda9ac commit 8e151df

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

‎src/LiveDevelopment/MultiBrowserImpl/documents/LiveDocument.js‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

‎src/styles/Extn-LayersPanel.less‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,10 @@
520520
box-shadow: inset 2px 0 0 fade(@layers-accent, 40%);
521521
}
522522

523+
&.layers-caret-target {
524+
box-shadow: inset 0 0 0 1px fade(@layers-accent, 55%);
525+
}
526+
523527
&.layers-holds-selected {
524528
background: @layers-row-holder-bg;
525529
}

0 commit comments

Comments
 (0)