Skip to content

Commit 5734768

Browse files
committed
feat: enable redo when ctrl + y is pressed in live preview
1 parent d851f1d commit 5734768

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

src/LiveDevelopment/BrowserScripts/LiveDevProtocolRemote.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,14 @@
447447
undoLivePreviewOperation: true
448448
});
449449
}
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+
}
450458
});
451459

452460
}(this));

src/LiveDevelopment/LivePreviewEdit.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,25 @@ define(function (require, exports, module) {
217217
});
218218
}
219219

220+
/**
221+
* This function is to handle the undo redo operation in the live preview
222+
* @param {String} undoOrRedo - "undo" when to undo, and "redo" for redo
223+
*/
224+
function handleUndoRedoOperation(undoOrRedo) {
225+
const currLiveDoc = LiveDevMultiBrowser.getCurrentLiveDoc();
226+
if (!currLiveDoc || !currLiveDoc.editor) {
227+
return;
228+
}
229+
230+
const editor = currLiveDoc.editor;
231+
232+
if (undoOrRedo === "undo") {
233+
editor.undo();
234+
} else if (undoOrRedo === "redo") {
235+
editor.redo();
236+
}
237+
}
238+
220239
/**
221240
* This is the main function that is exported.
222241
* it will be called by LiveDevProtocol when it receives a message from RemoteFunctions.js
@@ -247,14 +266,8 @@ define(function (require, exports, module) {
247266

248267
if (!message.element || !message.tagId) {
249268
// check for undo
250-
if (message.undoLivePreviewOperation) {
251-
const currLiveDoc = LiveDevMultiBrowser.getCurrentLiveDoc();
252-
if (!currLiveDoc || !currLiveDoc.editor) {
253-
return;
254-
}
255-
256-
const editor = currLiveDoc.editor;
257-
editor.undo();
269+
if (message.undoLivePreviewOperation || message.redoLivePreviewOperation) {
270+
message.undoLivePreviewOperation ? handleUndoRedoOperation("undo") : handleUndoRedoOperation("redo");
258271
}
259272
return;
260273
}

0 commit comments

Comments
 (0)