|
128 | 128 | } |
129 | 129 | }; |
130 | 130 |
|
| 131 | + global._Brackets_MessageBroker = MessageBroker; |
| 132 | + |
131 | 133 | /** |
132 | 134 | * Runtime Domain. Implements remote commands for "Runtime.*" |
133 | 135 | */ |
|
390 | 392 | function onDocumentClick(event) { |
391 | 393 | // Get the user's current selection |
392 | 394 | 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 | | - } |
401 | 395 | var element = event.target; |
402 | 396 | 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 | + } |
412 | 439 | } |
413 | 440 | } |
414 | 441 | 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 | + }); |
415 | 459 |
|
416 | 460 | }(this)); |
0 commit comments