commit 4248a7250b7ec37d1c48ef895a6f2a69f458f12f
parent 6f14993bcda9c4e2baa7c167debf75052659e2e9
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Tue, 20 Aug 2024 16:02:20 -0700
Provide interface to undo and redo in editor
Diffstat:
3 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/files/floorplans/floorplan/main.js b/files/floorplans/floorplan/main.js
@@ -93,6 +93,30 @@ function init() {
.appendChild(document.createElement("ul"))
toolbar.classList.add("toolbar")
+ let undoRedo = document.createElement("li")
+ // These could be hidden when they wouldn't have any effect
+ undoRedo.append(ui.button("Undo",
+ "Undo last action (you may also press u or control-z)",
+ "arrow-undo-circle", {
+ handlers: {
+ click: function() {
+ editor.undo()
+ }
+ }
+ })
+ )
+ undoRedo.append(ui.button("Redo",
+ "Redo next action (you may also press r)",
+ "arrow-redo-circle", {
+ handlers: {
+ click: function() {
+ editor.redo()
+ }
+ }
+ })
+ )
+ toolbar.append(undoRedo)
+
toolbar.append(pushpull)
toolbar.append(item(
selector(editor, editor.modes, function(mode) { editor.useMode(mode) },
@@ -174,9 +198,29 @@ let modes = {
mousedown: preciseAddWallHandler,
mousemove: preciseAddWallHandler,
mouseup: preciseAddWallHandler,
- keydown: preciseAddWallHandler
+ keydown: [undoRedoHandler, preciseAddWallHandler]
+ }
+ }
+}
+
+// keydown
+function undoRedoHandler(event, editor) {
+ if (event.ctrlKey) {
+ if (event.key === "z") {
+ editor.undo()
+ } else {
+ return
+ }
+ } else {
+ if (event.key === "u") {
+ editor.undo()
+ } else if (event.key === "r") {
+ editor.redo()
+ } else {
+ return
}
}
+ event.preventDefault()
}
// mousedown, mousemove, mouseup, keydown
diff --git a/files/icons/arrow-redo-circle-outline.svg b/files/icons/arrow-redo-circle-outline.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512"><path d="M266.91,327.74V290.42c-57.07,0-84.51,13.47-108.58,38.68-5.4,5.65-15,1.32-14.29-6.43,5.45-61.45,34.14-117.09,122.87-117.09V168.26a8.32,8.32,0,0,1,14-6L365.42,242a8.2,8.2,0,0,1,0,11.94L281,333.71A8.32,8.32,0,0,1,266.91,327.74Z"/><path d="M64,256c0,106,86,192,192,192s192-86,192-192S362,64,256,64,64,150,64,256Z" style="fill:none;stroke:#000;stroke-miterlimit:10;stroke-width:32px"/></svg>
+\ No newline at end of file
diff --git a/files/icons/arrow-undo-circle-outline.svg b/files/icons/arrow-undo-circle-outline.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512"><path d="M245.09,327.74V290.42c57.07,0,84.51,13.47,108.58,38.68,5.4,5.65,15,1.32,14.29-6.43-5.45-61.45-34.14-117.09-122.87-117.09V168.26a8.32,8.32,0,0,0-14.05-6L146.58,242a8.2,8.2,0,0,0,0,11.94L231,333.71A8.32,8.32,0,0,0,245.09,327.74Z"/><path d="M256,64C150,64,64,150,64,256s86,192,192,192,192-86,192-192S362,64,256,64Z" style="fill:none;stroke:#000;stroke-miterlimit:10;stroke-width:32px"/></svg>
+\ No newline at end of file