From c4abbff496a78bb64f9f15d6b07edf2f6e3ca2a3 Mon Sep 17 00:00:00 2001 From: Sean Lip Date: Thu, 21 Jul 2016 16:48:08 -0700 Subject: [PATCH] Implement correct behaviour for copying a block from the toolbox to a marked spot. --- accessible/clipboard.service.js | 8 +--- accessible/toolbox-tree.component.js | 53 +++++++++++++++++--------- accessible/workspace-tree.component.js | 5 ++- 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/accessible/clipboard.service.js b/accessible/clipboard.service.js index a9be69eb5..6048e1c2c 100644 --- a/accessible/clipboard.service.js +++ b/accessible/clipboard.service.js @@ -116,7 +116,7 @@ blocklyApp.ClipboardService = ng.core Blockly.Msg.PASTED_BLOCK_FROM_CLIPBOARD_MSG + reconstitutedBlock.toString()); }, - pasteToMarkedConnection: function(block, announce) { + pasteToMarkedConnection: function(block) { var xml = Blockly.Xml.blockToDom(block); var reconstitutedBlock = Blockly.Xml.domToBlock( blocklyApp.workspace, xml); @@ -142,12 +142,6 @@ blocklyApp.ClipboardService = ng.core return; } - if (announce) { - alert( - Blockly.Msg.PASTED_BLOCK_TO_MARKED_SPOT_MSG + - reconstitutedBlock.toString()); - } - this.markedConnection_ = null; return reconstitutedBlock.id; diff --git a/accessible/toolbox-tree.component.js b/accessible/toolbox-tree.component.js index 1397e746d..e0d13424f 100644 --- a/accessible/toolbox-tree.component.js +++ b/accessible/toolbox-tree.component.js @@ -45,25 +45,26 @@ blocklyApp.ToolboxTreeComponent = ng.core [attr.aria-labelledBy]="generateAriaLabelledByAttr(idMap['workspaceCopyButton'], 'blockly-button')" [attr.aria-level]="level + 2" aria-selected="false">
  • -
  • @@ -136,22 +137,36 @@ blocklyApp.ToolboxTreeComponent = ng.core return this.utilsService.generateAriaLabelledByAttr( mainLabel, secondLabel, isDisabled); }, - canBeCopiedToMarkedConnection: function(block) { - return this.clipboardService.canBeCopiedToMarkedConnection(block); + canBeCopiedToMarkedConnection: function() { + return this.clipboardService.canBeCopiedToMarkedConnection(this.block); }, - copyToWorkspace: function(block) { - var xml = Blockly.Xml.blockToDom(block); + copyToWorkspace: function() { + var xml = Blockly.Xml.blockToDom(this.block); Blockly.Xml.domToBlock(blocklyApp.workspace, xml); - alert('Added block to workspace: ' + block.toString()); + alert('Added block to workspace: ' + this.block.toString()); }, - copyToClipboard: function(block) { - if (this.clipboardService) { - this.clipboardService.copy(block, true); - } + copyToClipboard: function() { + this.clipboardService.copy(this.block, true); }, - copyToMarkedSpot: function(block) { - if (this.clipboardService) { - this.clipboardService.pasteToMarkedConnection(block, true); - } + copyToMarkedSpot: function() { + // This involves two steps: + // - Put the block on the destination tree. + // - Change the current tree-level focus to the destination tree, and the + // screenreader focus for the destination tree to the block just moved. + var blockDescription = this.block.toString(); + + var newBlockId = this.clipboardService.pasteToMarkedConnection( + this.block); + + // Invoke a digest cycle, so that the DOM settles. + var that = this; + setTimeout(function() { + var destinationTreeId = that.treeService.getTreeIdForBlock(newBlockId); + document.getElementById(destinationTreeId).focus(); + that.treeService.setActiveDesc( + newBlockId + 'blockRoot', destinationTreeId); + + alert('Block copied to marked spot: ' + blockDescription); + }); } }); diff --git a/accessible/workspace-tree.component.js b/accessible/workspace-tree.component.js index 91c4c3a67..1d42d6a43 100644 --- a/accessible/workspace-tree.component.js +++ b/accessible/workspace-tree.component.js @@ -176,15 +176,18 @@ blocklyApp.WorkspaceTreeComponent = ng.core var blockDescription = this.block.toString(); var newBlockId = this.clipboardService.pasteToMarkedConnection( - this.block, false); + this.block); var that = this; this.removeBlockAndSetFocus_(this.block, function() { that.block.dispose(true); }); + // Invoke a digest cycle, so that the DOM settles. setTimeout(function() { var destinationTreeId = that.treeService.getTreeIdForBlock(newBlockId); + that.treeService.clearActiveDesc(destinationTreeId); + document.getElementById(destinationTreeId).focus(); that.treeService.setActiveDesc( newBlockId + 'blockRoot', destinationTreeId);