From adb506d4341262e1b8e3ffdb387ad5855f64d9a6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 15 Oct 2019 13:26:31 +0200 Subject: [PATCH] Positioning Shortcut keys working --- Canvas.js | 9 ++++++--- Spaces/ChartSpace.js | 4 ++-- Spaces/FloatingSpace.js | 12 ++++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Canvas.js b/Canvas.js index 98b7d1a56..8eae9a667 100644 --- a/Canvas.js +++ b/Canvas.js @@ -186,7 +186,6 @@ function newCanvas () { } function onKeyDown (event) { - event.preventDefault() if (event.altKey === true && event.code === 'ArrowUp') { thisObject.cockpitSpace.toTop() return @@ -239,13 +238,17 @@ function newCanvas () { if (event.ctrlKey === true) { if (event.keyCode >= 65 && event.keyCode <= 90) { + event.preventDefault() let nodeOnFocus = canvas.strategySpace.workspace.getNodeThatIsOnFocus() + let nodeUsingThisKey = canvas.strategySpace.workspace.getNodeByShortcutKey(event.key) + if (nodeOnFocus === undefined) { + /* Then we displace the whole workspace to center it at the node using this key */ + nodeUsingThisKey = canvas.floatingSpace.positionAtNode(nodeUsingThisKey) return } - let nodeUsingThisKey = canvas.strategySpace.workspace.getNodeByShortcutKey(event.key) - + /* If there is a node in focus, we try to assign the key to it. */ if (nodeUsingThisKey !== undefined) { if (nodeUsingThisKey.id === nodeOnFocus.id) { nodeOnFocus.payload.uiObject.shortcutKey = '' diff --git a/Spaces/ChartSpace.js b/Spaces/ChartSpace.js index a6faba6a5..763247dce 100644 --- a/Spaces/ChartSpace.js +++ b/Spaces/ChartSpace.js @@ -137,7 +137,7 @@ function newChartSpace () { function oneScreenLeft () { let displaceVector = { - x: -browserCanvas.width * PERCENTAGE_OF_SCREEN_FOR_DISPLACEMENT / 100, + x: browserCanvas.width * PERCENTAGE_OF_SCREEN_FOR_DISPLACEMENT / 100, y: 0 } @@ -146,7 +146,7 @@ function newChartSpace () { function oneScreenRight () { let displaceVector = { - x: +browserCanvas.width * PERCENTAGE_OF_SCREEN_FOR_DISPLACEMENT / 100, + x: -browserCanvas.width * PERCENTAGE_OF_SCREEN_FOR_DISPLACEMENT / 100, y: 0 } diff --git a/Spaces/FloatingSpace.js b/Spaces/FloatingSpace.js index f87dcd5da..f4f0f9574 100644 --- a/Spaces/FloatingSpace.js +++ b/Spaces/FloatingSpace.js @@ -17,6 +17,7 @@ function newFloatingSpace () { oneScreenDown: oneScreenDown, oneScreenLeft: oneScreenLeft, oneScreenRight: oneScreenRight, + positionAtNode: positionAtNode, fitIntoVisibleArea: fitIntoVisibleArea, isThisPointVisible: isThisPointVisible, makeVisible: makeVisible, @@ -135,6 +136,17 @@ function newFloatingSpace () { thisObject.container.displace(displaceVector) } + function positionAtNode (node) { + let position = thisObject.container.frame.frameThisPoint(node.payload.position) + + let displaceVector = { + x: browserCanvas.width / 2 - position.x, + y: browserCanvas.height / 2 - position.y + } + + thisObject.container.displace(displaceVector) + } + function isThisPointVisible (point) { if (point.x > browserCanvas.width) { return false