Skip to content

Commit f66fc0f

Browse files
committed
deploy: 84352e3
1 parent aa4ecf1 commit f66fc0f

File tree

417 files changed

+236462
-126960
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

417 files changed

+236462
-126960
lines changed

LiveDevelopment/BrowserScripts/LiveDevProtocolRemote.js

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@
128128
}
129129
};
130130

131+
global._Brackets_MessageBroker = MessageBroker;
132+
131133
/**
132134
* Runtime Domain. Implements remote commands for "Runtime.*"
133135
*/
@@ -390,27 +392,69 @@
390392
function onDocumentClick(event) {
391393
// Get the user's current selection
392394
const selection = window.getSelection();
393-
394-
// Check if there is a selection
395-
if (selection.toString().length > 0) {
396-
// if there is any selection like text or others, we don't see it as a live selection event
397-
// Eg: user may selects ome text in live preview to copy, in which case we should nt treat it
398-
// as a live select.
399-
return;
400-
}
401395
var element = event.target;
402396
if (element && element.hasAttribute('data-brackets-id')) {
403-
MessageBroker.send({
404-
"tagId": element.getAttribute('data-brackets-id'),
405-
"nodeID": element.id,
406-
"nodeClassList": element.classList,
407-
"nodeName": element.nodeName,
408-
"allSelectors": _getAllInheritedSelectorsInOrder(element),
409-
"contentEditable": element.contentEditable === 'true',
410-
"clicked": true
411-
});
397+
// Check if it's a double-click for direct editing
398+
if (event.detail === 2 && !['INPUT', 'TEXTAREA', 'SELECT'].includes(element.tagName)) {
399+
// Double-click detected, enable direct editing
400+
// Make the element editable
401+
if (window._LD && window._LD.DOMEditHandler) {
402+
// Use the existing DOMEditHandler to handle the edit
403+
window._LD.startEditing(element);
404+
} else {
405+
MessageBroker.send({
406+
"tagId": element.getAttribute('data-brackets-id'),
407+
"nodeID": element.id,
408+
"nodeClassList": element.classList,
409+
"nodeName": element.nodeName,
410+
"allSelectors": _getAllInheritedSelectorsInOrder(element),
411+
"contentEditable": element.contentEditable === 'true',
412+
"clicked": true,
413+
"edit": true
414+
});
415+
}
416+
417+
// Prevent default behavior and stop propagation
418+
event.preventDefault();
419+
event.stopPropagation();
420+
} else {
421+
// Regular click, just send the information
422+
// Check if there is a selection
423+
if (selection.toString().length > 0) {
424+
// if there is any selection like text or others, we don't see it as a live selection event
425+
// Eg: user may selects ome text in live preview to copy, in which case we should nt treat it
426+
// as a live select.
427+
return;
428+
}
429+
MessageBroker.send({
430+
"tagId": element.getAttribute('data-brackets-id'),
431+
"nodeID": element.id,
432+
"nodeClassList": element.classList,
433+
"nodeName": element.nodeName,
434+
"allSelectors": _getAllInheritedSelectorsInOrder(element),
435+
"contentEditable": element.contentEditable === 'true',
436+
"clicked": true
437+
});
438+
}
412439
}
413440
}
414441
window.document.addEventListener("click", onDocumentClick);
442+
window.document.addEventListener("keydown", function (e) {
443+
// for undo. refer to LivePreviewEdit.js file 'handleLivePreviewEditOperation' function
444+
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "z") {
445+
MessageBroker.send({
446+
livePreviewEditEnabled: true,
447+
undoLivePreviewOperation: true
448+
});
449+
}
450+
451+
// for redo
452+
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "y") {
453+
MessageBroker.send({
454+
livePreviewEditEnabled: true,
455+
redoLivePreviewOperation: true
456+
});
457+
}
458+
});
415459

416460
}(this));

LiveDevelopment/BrowserScripts/LivePreviewTransportRemote.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,37 @@
103103
}
104104
}
105105

106+
function createLRU(max = 100) {
107+
const map = new Map();
108+
109+
return {
110+
set: function (key, value = true) {
111+
if (map.has(key)) {
112+
map.delete(key); // refresh order
113+
}
114+
map.set(key, value);
115+
if (map.size > max) {
116+
const oldestKey = map.keys().next().value;
117+
map.delete(oldestKey);
118+
}
119+
},
120+
has: function (key) {
121+
if (!map.has(key)) {
122+
return false;
123+
}
124+
const val = map.get(key);
125+
map.delete(key); // refresh order
126+
map.set(key, val);
127+
return true;
128+
},
129+
size: function() {
130+
return map.size;
131+
}
132+
};
133+
}
134+
135+
const processedMessageIDs = createLRU(1000);
136+
106137
const clientID = "" + Math.round( Math.random()*1000000000);
107138

108139
const worker = new Worker(TRANSPORT_CONFIG.LIVE_DEV_REMOTE_WORKER_SCRIPTS_FILE_NAME);
@@ -218,7 +249,12 @@
218249
case 'MESSAGE_FROM_PHOENIX':
219250
if (self._callbacks && self._callbacks.message) {
220251
const clientIDs = event.data.clientIDs,
221-
message = event.data.message;
252+
message = event.data.message,
253+
messageID = event.data.messageID;
254+
if(messageID && processedMessageIDs.has(messageID)){
255+
return; // we have already processed this message.
256+
}
257+
processedMessageIDs.set(messageID, true);
222258
if(clientIDs.includes(clientID) || clientIDs.length === 0){
223259
// clientIDs.length = 0 if the message is intended for all clients
224260
self._callbacks.message(message);
@@ -264,6 +300,7 @@
264300
_postLivePreviewMessage({
265301
type: 'BROWSER_MESSAGE',
266302
clientID: clientID,
303+
messageID: crypto.randomUUID(),
267304
message: msgStr
268305
});
269306
},

0 commit comments

Comments
 (0)