Skip to content

Commit cf6c584

Browse files
committed
refactor: shortcuts processor out as its not active in core context
1 parent 5d0e848 commit cf6c584

File tree

3 files changed

+4
-117
lines changed

3 files changed

+4
-117
lines changed

src/LiveDevelopment/BrowserScripts/LiveDevProtocolRemote.js

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -538,119 +538,5 @@
538538
}
539539
}
540540
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-
});
655541

656542
}(this));

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function RemoteFunctions(config = {}) {
2121
// this is just a test function here to check if live preview. fn call is working correctly.
2222
console.log("Hello World", param);
2323
});
24+
const MessageBroker = window._Brackets_MessageBroker; // to be used by plugins.
2425

2526
const SHARED_STATE = {
2627
__description: "Use this to keep shared state for Live Preview Edit instead of window.*"
@@ -753,7 +754,7 @@ function RemoteFunctions(config = {}) {
753754

754755
// send cursor movement message to editor so cursor jumps to clicked element
755756
if (element.hasAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR)) {
756-
window._Brackets_MessageBroker.send({
757+
MessageBroker.send({
757758
"tagId": element.getAttribute(GLOBALS.DATA_BRACKETS_ID_ATTR),
758759
"nodeID": element.id,
759760
"nodeClassList": element.classList,
@@ -1285,7 +1286,7 @@ function RemoteFunctions(config = {}) {
12851286
// we need to refresh the config once the load is completed
12861287
// this is important because messageBroker gets ready for use only when load fires
12871288
window.addEventListener('load', function() {
1288-
window._Brackets_MessageBroker.send({
1289+
MessageBroker.send({
12891290
requestConfigRefresh: true
12901291
});
12911292
});

tracking-repos.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"phoenixPro": {
3-
"commitID": "362d14dffdbac13b851d4591ee07dd9827bb1c33"
3+
"commitID": "127d420d97cc208ec5840bc1278ae76829aaa427"
44
}
55
}

0 commit comments

Comments
 (0)