Skip to content

Commit 8d1d5ee

Browse files
committed
fix: undo redo on preview text inputs leaking to editor
1 parent 3bfcd58 commit 8d1d5ee

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/LiveDevelopment/BrowserScripts/LiveDevProtocolRemote.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -445,29 +445,13 @@
445445
}
446446
window.document.addEventListener("click", onDocumentClick);
447447
window.document.addEventListener("keydown", function (e) {
448-
// for undo. refer to LivePreviewEdit.js file 'handleLivePreviewEditOperation' function
449-
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "z" && !e.shiftKey) {
450-
MessageBroker.send({
451-
livePreviewEditEnabled: true,
452-
undoLivePreviewOperation: true
453-
});
454-
}
455-
456-
// for redo - supports both Ctrl+Y and Ctrl+Shift+Z (Cmd+Y and Cmd+Shift+Z on Mac)
457-
if ((e.ctrlKey || e.metaKey) && (e.key.toLowerCase() === "y" || (e.key.toLowerCase() === "z" && e.shiftKey))) {
458-
MessageBroker.send({
459-
livePreviewEditEnabled: true,
460-
redoLivePreviewOperation: true
461-
});
462-
}
463-
464448
// Check if user is editing text content - if so, allow normal text cut
465449
// Get the truly active element, even if inside shadow roots
466450
let activeElement = document.activeElement;
467451

468452
const isEditingText = activeElement && (
469453
// Check for standard form input elements
470-
['INPUT', 'TEXTAREA', 'SELECT', 'OPTION'].includes(activeElement.tagName) ||
454+
['INPUT', 'TEXTAREA'].includes(activeElement.tagName) ||
471455
// Check for contentEditable elements
472456
activeElement.isContentEditable ||
473457
// Check for ARIA roles that indicate text input
@@ -476,6 +460,24 @@
476460
(activeElement.hasAttribute("contenteditable") && activeElement.hasAttribute("data-brackets-id"))
477461
);
478462
const isInEditMode = window._LD && window._LD.getMode && window._LD.getMode() === 'edit';
463+
464+
// for undo. refer to LivePreviewEdit.js file 'handleLivePreviewEditOperation' function
465+
if (!isEditingText && isInEditMode && (e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "z" && !e.shiftKey) {
466+
MessageBroker.send({
467+
livePreviewEditEnabled: true,
468+
undoLivePreviewOperation: true
469+
});
470+
}
471+
472+
// for redo - supports both Ctrl+Y and Ctrl+Shift+Z (Cmd+Y and Cmd+Shift+Z on Mac)
473+
if (!isEditingText && isInEditMode && (e.ctrlKey || e.metaKey) &&
474+
(e.key.toLowerCase() === "y" || (e.key.toLowerCase() === "z" && e.shiftKey))) {
475+
MessageBroker.send({
476+
livePreviewEditEnabled: true,
477+
redoLivePreviewOperation: true
478+
});
479+
}
480+
479481
// Cut: Ctrl+X / Cmd+X - operates on selected element
480482
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "x") {
481483

0 commit comments

Comments
 (0)