From f4dbd766511ac659ea2c49a50174f6f0b0fd3afe Mon Sep 17 00:00:00 2001 From: Aayush Raj Date: Fri, 5 Apr 2024 22:39:21 +0530 Subject: [PATCH] add undo/redo shortcut and idea selection-indicator to LabyrinthJS While linking ideas, no selection-indicator of selected idea was visible thereby creating confusion. Added a selection-indicator to the currently selected idea and auto-deselect after making a link. Signed-off-by: Aayush Raj --- activities/LabyrinthJS.activity/js/activity.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/activities/LabyrinthJS.activity/js/activity.js b/activities/LabyrinthJS.activity/js/activity.js index 2743af72b..7ed7ffd04 100644 --- a/activities/LabyrinthJS.activity/js/activity.js +++ b/activities/LabyrinthJS.activity/js/activity.js @@ -362,11 +362,18 @@ define(["sugar-web/activity/activity", "l10n", "sugar-web/datastore", "sugar-web if (lastSelected == this) lastSelected = null; return; } else if (currentMode == 1) { + if (isSelectedNode(this)) { + unselectNode(this); + lastSelected = null; + } + else { selectNode(this); } if (lastSelected != null && lastSelected != this) { createEdge(lastSelected, this); + unselectNode(this); + lastSelected = null; pushState(); } - lastSelected = this; + if (isSelectedNode(this)) lastSelected = this; return; } else { if (isSelectedNode(this)) { @@ -639,6 +646,14 @@ define(["sugar-web/activity/activity", "l10n", "sugar-web/datastore", "sugar-web undoButton.addEventListener('click', function () { undoState(); }, true); var redoButton = document.getElementById("redo-button"); redoButton.addEventListener('click', function () { redoState(); }, true); + document.addEventListener('keydown', function (event) { + if (event.ctrlKey && event.key === 'z' || event.key === 'Z') { + undoState(); + } + if (event.ctrlKey && (event.key === 'y' || event.key === 'Y')) { + redoState(); + } + }); var reinitState = function() { stateHistory = [];