From 21f15aca486a5f226dd69cd1bfdae00b99b4d52b Mon Sep 17 00:00:00 2001 From: Sean Lip Date: Thu, 21 Jul 2016 16:29:52 -0700 Subject: [PATCH] Show alert when block is deleted. Prevent errors from happening when a block is deleted from a field. --- accessible/workspace-tree.component.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/accessible/workspace-tree.component.js b/accessible/workspace-tree.component.js index fdf4c2373..c27835b29 100644 --- a/accessible/workspace-tree.component.js +++ b/accessible/workspace-tree.component.js @@ -106,12 +106,13 @@ blocklyApp.WorkspaceTreeComponent = ng.core isIsolatedTopLevelBlock_: function(block) { // Returns whether the given block is at the top level, and has no // siblings. - return Boolean( - !block.nextConnection.targetConnection && - !block.previousConnection.targetConnection && - blocklyApp.workspace.topBlocks_.some(function(topBlock) { - return topBlock.id == block.id; - })); + var blockIsAtTopLevel = !block.getParent(); + var blockHasNoSiblings = ( + (!block.nextConnection || + !block.nextConnection.targetConnection) && + (!block.previousConnection || + !block.previousConnection.targetConnection)); + return blockIsAtTopLevel && blockHasNoSiblings; }, removeBlockAndSetFocus_: function(block, deleteBlockFunc) { // This method runs the given function and then does one of two things: @@ -139,10 +140,14 @@ blocklyApp.WorkspaceTreeComponent = ng.core }); }, deleteBlock_: function() { + var blockDescription = this.block.toString(); + var that = this; this.removeBlockAndSetFocus_(this.block, function() { that.block.dispose(true); }); + + alert('Block deleted: ' + blockDescription); }, pasteToConnection_: function(connection) { var that = this;