Skip to content

Commit 6ee04fb

Browse files
committed
fix: css reverse highlight shouldnt happen when forward highlight is going on
1 parent 827e395 commit 6ee04fb

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

src/LiveDevelopment/MultiBrowserImpl/documents/LiveDocument.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,17 @@ define(function (require, exports, module) {
171171
}
172172
};
173173

174+
let _disableHighlightOnCursor = false;
175+
176+
/**
177+
* If tur, it will disable highlights in live preview on cursor movement in editor
178+
* @param {boolean} shouldDisable
179+
*/
180+
LiveDocument.prototype.disableHighlightOnCursorActivity = function (shouldDisable) {
181+
// intentionally global. see usage for details
182+
_disableHighlightOnCursor = shouldDisable;
183+
};
184+
174185
/**
175186
* @private
176187
* Handles a cursor change in our attached editor. Updates the highlight in the browser.
@@ -181,7 +192,10 @@ define(function (require, exports, module) {
181192
if (!this.editor) {
182193
return;
183194
}
184-
this.updateHighlight();
195+
if(!_disableHighlightOnCursor){
196+
console.log("cursor activity highlight");
197+
this.updateHighlight();
198+
}
185199
};
186200

187201
/**

src/LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,21 @@ define(function (require, exports, module) {
342342
}
343343
}
344344
} else if (msg.clicked && msg.tagId) {
345-
_tagSelectedInLivePreview(msg.tagId, msg.nodeName, msg.contentEditable, msg.allSelectors);
346-
exports.trigger(EVENT_LIVE_PREVIEW_CLICKED, msg);
345+
// While previewing an html file, and if css related file is active in the editor, then clicking on the
346+
// live preview, here we set the cursor position in the css file. but this will also trigger a css
347+
// highlight as the cursor changes which jumps the live preview selection.
348+
// We should not do reverse highlight when lp highlight is going on here.
349+
const livePreviewMode = PreferencesManager.get(CONSTANTS.PREFERENCE_LIVE_PREVIEW_MODE);
350+
const editMode = (livePreviewMode === CONSTANTS.LIVE_PREVIEW_MODE);
351+
const liveDoc = LiveDevMultiBrowser.getCurrentLiveDoc();
352+
editMode && liveDoc && liveDoc.disableHighlightOnCursorActivity(true);
353+
try {
354+
_tagSelectedInLivePreview(msg.tagId, msg.nodeName, msg.contentEditable, msg.allSelectors);
355+
exports.trigger(EVENT_LIVE_PREVIEW_CLICKED, msg);
356+
} catch (e) {
357+
console.error("error in tag selection", e);
358+
}
359+
editMode && liveDoc && liveDoc.disableHighlightOnCursorActivity(false);
347360
} else {
348361
// enrich received message with clientId
349362
msg.clientId = clientId;

0 commit comments

Comments
 (0)