Skip to content

Commit 5e9c5c6

Browse files
committed
fix: cursor not getting positioned properly on element click in edit mode
1 parent f4d4541 commit 5e9c5c6

2 files changed

Lines changed: 36 additions & 10 deletions

File tree

src/LiveDevelopment/BrowserScripts/LiveDevProtocolRemote.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@
363363
ProtocolManager.enable();
364364
});
365365

366-
function _getAllInheritedSelectorsInOrder(element) {
366+
function getAllInheritedSelectorsInOrder(element) {
367367
let selectorsFound= new Map();
368368
const selectorsList = [];
369369
while (element) {
@@ -383,6 +383,7 @@
383383
return selectorsList;
384384
}
385385

386+
global.getAllInheritedSelectorsInOrder = getAllInheritedSelectorsInOrder;
386387

387388
/**
388389
* Sends the message containing tagID which is being clicked
@@ -407,7 +408,7 @@
407408
"nodeID": element.id,
408409
"nodeClassList": element.classList,
409410
"nodeName": element.nodeName,
410-
"allSelectors": _getAllInheritedSelectorsInOrder(element),
411+
"allSelectors": getAllInheritedSelectorsInOrder(element),
411412
"contentEditable": element.contentEditable === 'true',
412413
"clicked": true,
413414
"edit": true
@@ -431,7 +432,7 @@
431432
"nodeID": element.id,
432433
"nodeClassList": element.classList,
433434
"nodeName": element.nodeName,
434-
"allSelectors": _getAllInheritedSelectorsInOrder(element),
435+
"allSelectors": getAllInheritedSelectorsInOrder(element),
435436
"contentEditable": element.contentEditable === 'true',
436437
"clicked": true
437438
});

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3918,16 +3918,42 @@ function RemoteFunctions(config = {}) {
39183918
}, 800);
39193919
}
39203920

3921+
/**
3922+
* this function is called when user clicks on an element in the LP when in edit mode
3923+
*
3924+
* @param {HTMLElement} element - The clicked element
3925+
* @param {Event} event - The click event
3926+
*/
3927+
function handleElementClick(element, event) {
3928+
if (!isElementInspectable(element)) { return; }
3929+
3930+
// send cursor movement message to editor so cursor jumps to clicked element
3931+
if (element.hasAttribute("data-brackets-id")) {
3932+
const selection = window.getSelection();
3933+
3934+
if (!selection || selection.toString().length === 0) {
3935+
window._Brackets_MessageBroker.send({
3936+
"tagId": element.getAttribute("data-brackets-id"),
3937+
"nodeID": element.id,
3938+
"nodeClassList": element.classList,
3939+
"nodeName": element.nodeName,
3940+
"allSelectors": window.getAllInheritedSelectorsInOrder(element),
3941+
"contentEditable": element.contentEditable === "true",
3942+
"clicked": true
3943+
});
3944+
}
3945+
}
3946+
3947+
// call the selectElement as selectElement handles all the highlighting/boxes and all UI related stuff
3948+
_selectElement(element);
3949+
activateHoverLock();
3950+
}
3951+
39213952
/**
39223953
* this acts as the "KILL SWITCH", it blocks all the click related events from user elements
39233954
* but we exclude all the phoenix interal elements
39243955
* we call this function from inside registerHandlers
39253956
*/
3926-
/**
3927-
* Central event blocker for edit mode
3928-
* Blocks all user page interactions but allows Phoenix UI to work
3929-
* Stores handler references so they can be removed when switching modes
3930-
*/
39313957
function registerInteractionBlocker() {
39323958
// Create an object to store handler references
39333959
_interactionBlockerHandlers = {};
@@ -3953,8 +3979,7 @@ function RemoteFunctions(config = {}) {
39533979
// Skip click handling on the second click of a double-click
39543980
// event.detail = 1 for first click, 2 for second click (during double-click)
39553981
if (event.detail !== 2) {
3956-
_selectElement(element);
3957-
activateHoverLock();
3982+
handleElementClick(element, event);
39583983
}
39593984
} else if (eventType === "dblclick") {
39603985
if (isElementEditable(element) && _shouldShowEditTextOption(element)) {

0 commit comments

Comments
 (0)