|
538 | 538 | } |
539 | 539 | } |
540 | 540 | window.document.addEventListener("click", onDocumentClick); |
541 | | - window.document.addEventListener("keydown", function (e) { |
542 | | - // Check if user is editing text content - if so, allow normal text cut |
543 | | - // Get the truly active element, even if inside shadow roots |
544 | | - let activeElement = document.activeElement; |
545 | | - |
546 | | - const isEditingText = activeElement && ( |
547 | | - // Check for standard form input elements |
548 | | - ['INPUT', 'TEXTAREA'].includes(activeElement.tagName) || |
549 | | - // Check for contentEditable elements |
550 | | - activeElement.isContentEditable || |
551 | | - // Check for ARIA roles that indicate text input |
552 | | - ['textbox', 'searchbox', 'combobox'].includes(activeElement.getAttribute('role')) || |
553 | | - // Check if element is designed to receive text input |
554 | | - (activeElement.hasAttribute("contenteditable") && activeElement.hasAttribute("data-brackets-id")) |
555 | | - ); |
556 | | - |
557 | | - // Check if a Phoenix tool is active (has data-phcode-internal-* attribute) |
558 | | - const isActiveElementPhoenixTool = activeElement && Array.from(activeElement.attributes || []).some(attr => |
559 | | - attr.name.startsWith('data-phcode-internal-') && attr.value === 'true' |
560 | | - ); |
561 | | - |
562 | | - const isInEditMode = window._LD && window._LD.getMode && window._LD.getMode() === 'edit'; |
563 | | - |
564 | | - // for undo. refer to LivePreviewEdit.js file 'handleLivePreviewEditOperation' function |
565 | | - if (!isEditingText && !isActiveElementPhoenixTool && isInEditMode && |
566 | | - (e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "z" && !e.shiftKey) { |
567 | | - MessageBroker.send({ |
568 | | - livePreviewEditEnabled: true, |
569 | | - undoLivePreviewOperation: true |
570 | | - }); |
571 | | - } |
572 | | - |
573 | | - // for redo - supports both Ctrl+Y and Ctrl+Shift+Z (Cmd+Y and Cmd+Shift+Z on Mac) |
574 | | - if (!isEditingText && !isActiveElementPhoenixTool && isInEditMode && (e.ctrlKey || e.metaKey) && |
575 | | - (e.key.toLowerCase() === "y" || (e.key.toLowerCase() === "z" && e.shiftKey))) { |
576 | | - MessageBroker.send({ |
577 | | - livePreviewEditEnabled: true, |
578 | | - redoLivePreviewOperation: true |
579 | | - }); |
580 | | - } |
581 | | - |
582 | | - // Cut: Ctrl+X / Cmd+X - operates on selected element |
583 | | - if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "x") { |
584 | | - |
585 | | - // Only handle element cut if not editing text and in edit mode |
586 | | - if (!isEditingText && !isActiveElementPhoenixTool && isInEditMode && window._LD.handleCutElement) { |
587 | | - e.preventDefault(); |
588 | | - window._LD.handleCutElement(); |
589 | | - } |
590 | | - } |
591 | | - |
592 | | - // duplicate element: Ctrl+D / Cmd+D |
593 | | - if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "d") { |
594 | | - |
595 | | - // Only handle element cut if not editing text and in edit mode |
596 | | - if (!isEditingText && !isActiveElementPhoenixTool && isInEditMode && window._LD.handleCutElement) { |
597 | | - e.preventDefault(); |
598 | | - window._LD.handleDuplicateElement(); |
599 | | - } |
600 | | - } |
601 | | - |
602 | | - // Copy: Ctrl+C / Cmd+C - operates on selected element |
603 | | - if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "c") { |
604 | | - |
605 | | - // Only handle element copy if not editing text and in edit mode |
606 | | - if (!isEditingText && !isActiveElementPhoenixTool && isInEditMode && window._LD.handleCopyElement) { |
607 | | - e.preventDefault(); |
608 | | - window._LD.handleCopyElement(); |
609 | | - } |
610 | | - } |
611 | | - |
612 | | - // Paste: Ctrl+V / Cmd+V - operates on selected element |
613 | | - if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "v") { |
614 | | - |
615 | | - // Only handle element paste if not editing text and in edit mode |
616 | | - if (!isEditingText && !isActiveElementPhoenixTool && isInEditMode && window._LD.handlePasteElement) { |
617 | | - e.preventDefault(); |
618 | | - window._LD.handlePasteElement(); |
619 | | - } |
620 | | - } |
621 | | - |
622 | | - if (e.key.toLowerCase() === 'delete' || e.key.toLowerCase() === 'backspace') { |
623 | | - if (!isEditingText && !isActiveElementPhoenixTool && isInEditMode && window._LD.handleDeleteElement) { |
624 | | - e.preventDefault(); |
625 | | - window._LD.handleDeleteElement(); |
626 | | - } |
627 | | - } |
628 | | - |
629 | | - // for save |
630 | | - if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "s") { |
631 | | - e.preventDefault(); |
632 | | - |
633 | | - // to check if user was in between editing text |
634 | | - // in such cases we first finish the editing and then save |
635 | | - if (isEditingText && window._LD && window._LD.finishEditing) { |
636 | | - |
637 | | - window._LD.finishEditing(activeElement); |
638 | | - } |
639 | | - |
640 | | - MessageBroker.send({ |
641 | | - livePreviewEditEnabled: true, |
642 | | - saveCurrentDocument: true |
643 | | - }); |
644 | | - } |
645 | | - |
646 | | - // for preview button (play icon) toggle |
647 | | - if (e.key === 'F8') { |
648 | | - e.preventDefault(); |
649 | | - MessageBroker.send({ |
650 | | - livePreviewEditEnabled: true, |
651 | | - toggleLivePreviewMode: true |
652 | | - }); |
653 | | - } |
654 | | - }); |
655 | 541 |
|
656 | 542 | }(this)); |
0 commit comments