From 75a842b884b1a789edcbdca5bf4fa2dde6ef7099 Mon Sep 17 00:00:00 2001 From: Sean Lip Date: Mon, 1 Aug 2016 19:20:20 -0700 Subject: [PATCH] Refactor common functionality. Focus on new blocks immediately after they are created. Fix active descendant for tricky cases where moving a block to a marked spot splits the existing tree. --- accessible/clipboard.service.js | 26 ++++++++++---- accessible/toolbox-tree.component.js | 37 ++++++++++++------- accessible/tree.service.js | 35 ++++++++++++------ accessible/workspace-tree.component.js | 50 ++++++++++---------------- 4 files changed, 85 insertions(+), 63 deletions(-) diff --git a/accessible/clipboard.service.js b/accessible/clipboard.service.js index 3aec5cc11..4ae568b26 100644 --- a/accessible/clipboard.service.js +++ b/accessible/clipboard.service.js @@ -26,8 +26,9 @@ blocklyApp.ClipboardService = ng.core .Class({ constructor: [blocklyApp.UtilsService, function(_utilsService) { this.clipboardBlockXml_ = null; - this.clipboardBlockSuperiorConnection_ = null; + this.clipboardBlockPreviousConnection_ = null; this.clipboardBlockNextConnection_ = null; + this.clipboardBlockOutputConnection_ = null; this.markedConnection_ = null; this.utilsService = _utilsService; }], @@ -40,11 +41,13 @@ blocklyApp.ClipboardService = ng.core connection.checkType_(blockConnection)); }, isCompatibleWithClipboard: function(connection) { - var superiorConnection = this.clipboardBlockSuperiorConnection_; + var previousConnection = this.clipboardBlockPreviousConnection_; var nextConnection = this.clipboardBlockNextConnection_; + var outputConnection = this.clipboardBlockOutputConnection_; return Boolean( - this.areConnectionsCompatible_(connection, superiorConnection) || - this.areConnectionsCompatible_(connection, nextConnection)); + this.areConnectionsCompatible_(connection, previousConnection) || + this.areConnectionsCompatible_(connection, nextConnection) || + this.areConnectionsCompatible_(connection, outputConnection)); }, getMarkedConnectionBlock: function() { if (!this.markedConnection_) { @@ -98,9 +101,9 @@ blocklyApp.ClipboardService = ng.core }, copy: function(block, announce) { this.clipboardBlockXml_ = Blockly.Xml.blockToDom(block); - this.clipboardBlockSuperiorConnection_ = block.outputConnection || - block.previousConnection; + this.clipboardBlockPreviousConnection_ = block.previousConnection; this.clipboardBlockNextConnection_ = block.nextConnection; + this.clipboardBlockOutputConnection_ = block.outputConnection; if (announce) { alert( @@ -108,7 +111,16 @@ blocklyApp.ClipboardService = ng.core this.utilsService.getBlockDescription(block)); } }, - pasteFromClipboard: function(connection) { + pasteFromClipboard: function(inputConnection) { + var connection = inputConnection; + // 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 (inputConnection.type == Blockly.PREVIOUS_STATEMENT && + inputConnection.isConnected()) { + connection = inputConnection.targetConnection; + } + var reconstitutedBlock = Blockly.Xml.domToBlock(blocklyApp.workspace, this.clipboardBlockXml_); switch (connection.type) { diff --git a/accessible/toolbox-tree.component.js b/accessible/toolbox-tree.component.js index ee1486029..40e28df87 100644 --- a/accessible/toolbox-tree.component.js +++ b/accessible/toolbox-tree.component.js @@ -64,8 +64,9 @@ blocklyApp.ToolboxTreeComponent = ng.core +