From 633eeccd81499ea3c807fa813e5fb93bb1876361 Mon Sep 17 00:00:00 2001 From: Yi-Ting Tu Date: Mon, 14 Oct 2024 16:19:45 -0400 Subject: [PATCH] Fix Ctrl+D error --- src/simulator/js/app.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/simulator/js/app.js b/src/simulator/js/app.js index ef690e0e..68589ac0 100644 --- a/src/simulator/js/app.js +++ b/src/simulator/js/app.js @@ -374,14 +374,16 @@ async function startApp() { } //Ctrl+D if (e.ctrlKey && e.keyCode == 68) { - if (scene.objs[editor.selectedObjIndex].constructor.type == 'Handle') { - scene.cloneObjsByHandle(editor.selectedObjIndex); - } else { - scene.cloneObj(editor.selectedObjIndex); - } + if (editor.selectedObjIndex != -1) { + if (scene.objs[editor.selectedObjIndex].constructor.type == 'Handle') { + scene.cloneObjsByHandle(editor.selectedObjIndex); + } else { + scene.cloneObj(editor.selectedObjIndex); + } - simulator.updateSimulation(!scene.objs[editor.selectedObjIndex].constructor.isOptical, true); - editor.onActionComplete(); + simulator.updateSimulation(!scene.objs[editor.selectedObjIndex].constructor.isOptical, true); + editor.onActionComplete(); + } return false; } //Ctrl+Y