From 0e7e3547b93f18cd64ae6cac38b49f92c1c07659 Mon Sep 17 00:00:00 2001 From: Sean Lip Date: Fri, 22 Jul 2016 17:49:11 -0700 Subject: [PATCH] Fix screenreader focus behaviour when pasting blocks. --- accessible/workspace-tree.component.js | 38 +++++++++++++++----------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/accessible/workspace-tree.component.js b/accessible/workspace-tree.component.js index 7d5ac4486..d36bde6e2 100644 --- a/accessible/workspace-tree.component.js +++ b/accessible/workspace-tree.component.js @@ -149,24 +149,30 @@ blocklyApp.WorkspaceTreeComponent = ng.core alert('Block deleted: ' + blockDescription); }, pasteToConnection_: function(connection) { + // 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 newBlockId = null; + + // If the connection is a 'previousConnection' and that connection is + // already joined to something, use the 'nextConnection' of the + // previous block instead in order to do an insertion. + if (connection.type == Blockly.PREVIOUS_STATEMENT && + connection.isConnected()) { + newBlockId = this.clipboardService.pasteFromClipboard( + connection.targetConnection); + } else { + newBlockId = this.clipboardService.pasteFromClipboard(connection); + } + + // Invoke a digest cycle, so that the DOM settles. var that = this; - this.treeService.runWhilePreservingFocus(function() { - // If the connection is a 'previousConnection' and that connection is - // already joined to something, use the 'nextConnection' of the - // previous block instead in order to do an insertion. - var newBlockId = null; - - if (connection.type == Blockly.PREVIOUS_STATEMENT && - connection.isConnected()) { - newBlockId = that.clipboardService.pasteFromClipboard( - connection.targetConnection); - } else { - newBlockId = that.clipboardService.pasteFromClipboard(connection); - } - + setTimeout(function() { // Move the screenreader focus to the newly-pasted block. + that.treeService.clearActiveDesc(that.tree.id); that.treeService.setActiveDesc(newBlockId + 'blockRoot', that.tree.id); - }, this.tree.id); + }); }, moveToMarkedSpot_: function() { // This involves three steps: @@ -282,7 +288,7 @@ blocklyApp.WorkspaceTreeComponent = ng.core baseIdKey: 'paste', translationIdForText: 'PASTE', action: function(connection) { - that.clipboardService.pasteFromClipboard(connection); + that.pasteToConnection_(connection); }, isDisabled: function(connection) { return !that.isCompatibleWithClipboard(connection);