Skip to content

Commit 2e4e7ff

Browse files
committed
fix: major bug that used to recreate highlighting and box on every keystroke
1 parent 0fa18d1 commit 2e4e7ff

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ function RemoteFunctions(config = {}) {
3333
// we need this so that we can remove click styling from the previous element when a new element is clicked
3434
let previouslyClickedElement = null;
3535

36+
// this is needed so that when user starts typing we can dismiss all the boxes and highlights
37+
// now with this variable we check if its a first keystroke on an element or a subsequent keystroke
38+
let _uiHiddenDuringTyping = false;
39+
3640
var req, timeout;
3741
var animateHighlight = function (time) {
3842
if(req) {
@@ -1577,10 +1581,6 @@ function RemoteFunctions(config = {}) {
15771581
create: function() {
15781582
this.remove(); // remove existing box if already present
15791583

1580-
if(!config.isProUser) {
1581-
return;
1582-
}
1583-
15841584
// this check because when there is no element visible to the user, we don't want to show the box
15851585
// for ex: when user clicks on a 'x' button and the button is responsible to hide a panel
15861586
// then clicking on that button shouldn't show the more options box
@@ -3822,6 +3822,9 @@ function RemoteFunctions(config = {}) {
38223822
* @param {Element} element - The DOM element to select
38233823
*/
38243824
function _selectElement(element) {
3825+
// user selected a new element, we need to reset this variable
3826+
_uiHiddenDuringTyping = false;
3827+
38253828
dismissNodeMoreOptionsBox();
38263829
dismissAIPromptBox();
38273830
dismissNodeInfoBox();
@@ -3931,12 +3934,7 @@ function RemoteFunctions(config = {}) {
39313934
event.stopPropagation();
39323935
event.stopImmediatePropagation();
39333936

3934-
// when in click mode, only select dynamic elements (without data-brackets-id) directly
3935-
// as for static elements, the editor will handle selection via highlight message
3936-
if (!shouldShowHighlightOnHover() && !element.hasAttribute("data-brackets-id")) {
3937-
_selectElement(element);
3938-
}
3939-
3937+
_selectElement(element);
39403938
activateHoverLock();
39413939
}
39423940
}
@@ -4021,7 +4019,10 @@ function RemoteFunctions(config = {}) {
40214019
var foundValidElement = false;
40224020
for (i = 0; i < nodes.length; i++) {
40234021
if(isElementInspectable(nodes[i], true) && nodes[i].tagName !== "BR") {
4024-
_selectElement(nodes[i]);
4022+
// only call _selectElement if it's a different element to avoid unnecessary box recreation
4023+
if (previouslyClickedElement !== nodes[i]) {
4024+
_selectElement(nodes[i]);
4025+
}
40254026
foundValidElement = true;
40264027
break;
40274028
}
@@ -4431,8 +4432,14 @@ function RemoteFunctions(config = {}) {
44314432

44324433
this.rememberedNodes = {};
44334434

4434-
// update highlight after applying diffs
4435-
redrawEverything();
4435+
// when user starts typing in the editor we hide all the boxes and highlights
4436+
// _uiHiddenDuringTyping variable keeps track if its a first keystroke or subsequent
4437+
// so that we don't end up calling dismiss/hide kinda functions multiple times
4438+
if (!_uiHiddenDuringTyping) {
4439+
dismissUIAndCleanupState();
4440+
hideHighlight();
4441+
_uiHiddenDuringTyping = true;
4442+
}
44364443
};
44374444

44384445
function applyDOMEdits(edits) {

0 commit comments

Comments
 (0)