Insertion markers in Blockly!#1987
Insertion markers in Blockly!#1987rachel-fenichel merged 15 commits intoRaspberryPiFoundation:developfrom rachel-fenichel:feature/insertion_markers
Conversation
AnmAtAnm
left a comment
There was a problem hiding this comment.
Stepping back, is there any reason we need to support the original behavior for existing applications? Put another way, are we confident that this change is positive change for all developers and their users.
Off the top of my head, I can't think of any way in which the previous behavior is preferable, but I want our answer to be explicit and shared by everyone on our team.
core/block.js
Outdated
| } | ||
| this.isInsertionMarker_ = insertionMarker; | ||
| if (this.isInsertionMarker_) { | ||
| // TODO: Why is this in Block.js instead of block_svg.js? |
There was a problem hiding this comment.
Move this TODO/question to the the setColour method in block.js?
There was a problem hiding this comment.
As I said, this isn't for review yet. I'm not done with cleanup.
core/block_render_svg.js
Outdated
|
|
||
| /** | ||
| * Visual effect to show that if the dragging block is dropped, this block will | ||
| * be replaced. If a shadow block it will disappear. Otherwise it will bump. |
There was a problem hiding this comment.
Comma after
If a shadow block
blockly_uncompressed.js
Outdated
| @@ -34,82 +34,83 @@ this.BLOCKLY_BOOT = function(root) { | |||
| dir = this.BLOCKLY_DIR.match(/[^\/]+$/)[0]; | |||
| } | |||
| // Execute after Closure has loaded. | |||
| goog.addDependency("../../../" + dir + "/core/block.js", ['Blockly.Block'], ['Blockly.Blocks', 'Blockly.Comment', 'Blockly.Connection', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.Input', 'Blockly.Mutator', 'Blockly.Warning', 'Blockly.Workspace', 'Blockly.Xml', 'goog.array', 'goog.asserts', 'goog.math.Coordinate', 'goog.string']); | |||
There was a problem hiding this comment.
I know this is the only compressed file that should be impacted by your changes, but it doesn't seem right to only update one of the files. I would rather see all three updated in a single followup push.
There was a problem hiding this comment.
If I don't update this file it's not testable.
|
Two thoughts from my point of view:
1. Allowing for the old behavior would be nice. We will have to update videos and tutorial GIFs, which will take time, but I think App Inventor users would appreciate the new functionality. We did something similar with the grid and made it user toggleable.
2. The insertion marker is only the currently selected block. This doesn't seem quite right when dragging/inserting a stack of blocks since the to-be-displaced blocks move only for the size of the single block, not the whole stack. It would be nice if the blocks were displaced by the height of the whole stack.
… On Jul 26, 2018, at 21:57, Andrew n marshall ***@***.***> wrote:
@AnmAtAnm approved this pull request.
Stepping back, is there any reason we need to support the original behavior for existing applications? Put another way, are we confident that this change is positive change for all developers and their users.
Off the top of my head, I can't think of any way in which the previous behavior is preferable, but I want our answer to be explicit and shared by everyone on our team.
In core/block.js:
> + */
+Blockly.Block.prototype.isInsertionMarker = function() {
+ return this.isInsertionMarker_;
+};
+
+/**
+ * Set whether this block is an insertion marker block or not.
+ * @param {boolean} insertionMarker True if an insertion marker.
+ */
+Blockly.Block.prototype.setInsertionMarker = function(insertionMarker) {
+ if (this.isInsertionMarker_ == insertionMarker) {
+ return; // No change.
+ }
+ this.isInsertionMarker_ = insertionMarker;
+ if (this.isInsertionMarker_) {
+ // TODO: Why is this in Block.js instead of block_svg.js?
Move this TODO/question to the the setColour method in block.js?
In core/block_render_svg.js:
> +Blockly.BlockSvg.prototype.positionNewBlock = function(newBlock, newConnection,
+ existingConnection) {
+ // We only need to position the new block if it's before the existing one,
+ // otherwise its position is set by the previous block.
+ if (newConnection.type == Blockly.NEXT_STATEMENT ||
+ newConnection.type == Blockly.INPUT_VALUE) {
+ var dx = existingConnection.x_ - newConnection.x_;
+ var dy = existingConnection.y_ - newConnection.y_;
+
+ newBlock.moveBy(dx, dy);
+ }
+};
+
+/**
+ * Visual effect to show that if the dragging block is dropped, this block will
+ * be replaced. If a shadow block it will disappear. Otherwise it will bump.
Comma after
If a shadow block
In blockly_uncompressed.js:
> @@ -34,82 +34,83 @@ this.BLOCKLY_BOOT = function(root) {
dir = this.BLOCKLY_DIR.match(/[^\/]+$/)[0];
}
// Execute after Closure has loaded.
-goog.addDependency("../../../" + dir + "/core/block.js", ['Blockly.Block'], ['Blockly.Blocks', 'Blockly.Comment', 'Blockly.Connection', 'Blockly.Events.BlockChange', 'Blockly.Events.BlockCreate', 'Blockly.Events.BlockDelete', 'Blockly.Events.BlockMove', 'Blockly.Extensions', 'Blockly.Input', 'Blockly.Mutator', 'Blockly.Warning', 'Blockly.Workspace', 'Blockly.Xml', 'goog.array', 'goog.asserts', 'goog.math.Coordinate', 'goog.string']);
I know this is the only compressed file that should be impacted by your changes, but it doesn't seem right to only update one of the files. I would rather see all three updated in a single followup push.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
|
@ewpatton It was also a little jarring when you dragged a stack down another stack and everything kept jumping off the bottom of the page. We found just using a single block was less jumpy. It may be confusing for some users, though, since at first they might think only one block will be connected. |
|
This is a preliminary pull request to show what changes are required. I'm not planning to land anything until I'm happy with behaviour and appearance in all cases and we have a good developer story. Some information to consider:
My current plan is to leave Developers who want it to be user-configurable would be responsible for including both styles (easy to do) and piping the user's decision to the right place in Thoughts? |
|
@ewpatton for a working example of why the single-block behaviour is the right way to do it, hit the "Spaghetti" button and drag one of the if statements around inside the stack. It'll be slow, but you'll notice that you can move it down one block at a time, allowing you to insert it anywhere. If the insertion marker contains the entire stack, the next block would jump out of view. The jumpiness isn't just annoying: it makes it impossible to move the insertion marker down by a single block. Instead you have to drag it to the side until the marker disappears, then drag back to the stack at (hopefully) the correct place. |
|
@RoboErikG @rachel-fenichel Okay, that's sounds like a reasonable argument for the one blockly only approach. Thanks for the info. |
rachel-fenichel
left a comment
There was a problem hiding this comment.
These changes are now ready for review. I chose to make C-shape blocks always insert instead of wrapping. That choice isn't permanent: we may add more complex behaviour later.
core/block_dragger.js
Outdated
|
|
||
| // // During a drag there may be a lot of rerenders, but not field changes. | ||
| // // Turn the cache on so we don't do spurious remeasures during the drag. | ||
| // Blockly.Field.startCache(); |
There was a problem hiding this comment.
Did you forget to uncomment this line?
There was a problem hiding this comment.
Whoops, fixed in a commit that I forgot to push.
core/connection.js
Outdated
| * @return {boolean} true if the connection is not connected or is connected to | ||
| * an insertion marker, false otherwise. | ||
| */ | ||
| Blockly.Connection.prototype.isConnectedToNonInsertionMarker = function() { |
There was a problem hiding this comment.
This doesn't seem to be used anywhere. Also, what about connections that would be connected except there's an insertion marker between blocks?
core/connection.js
Outdated
| // marker is in the middle of a stack, it won't work. | ||
| return !targetBlock.getPreviousBlock(); | ||
| } | ||
| // ??? |
There was a problem hiding this comment.
!!!
I'm unsure of what cases would end up here. I think it's worth having a log statement here, which will let me debug until all cases are covered. Any objections?
|
I added tests; PTAL. |
RoboErikG
left a comment
There was a problem hiding this comment.
Some references to Scratch specific code in the comments that need to be cleaned up. Once that's done lgtm.
core/insertion_marker_manager.js
Outdated
|
|
||
| /** | ||
| * Get rid of the highlighting marking the block that will be replaced. | ||
| * Scratch-specific code, where "highlighting" applies to a block rather than |
There was a problem hiding this comment.
"Scratch-specific code" then why is it here?
core/insertion_marker_manager.js
Outdated
|
|
||
| /** | ||
| * Add highlighting showing which block will be replaced. | ||
| * Scratch-specific code, where "highlighting" applies to a block rather than |
There was a problem hiding this comment.
'Scratch specific code'?
core/insertion_marker_manager.js
Outdated
| /** | ||
| * The insertion marker that shows up between blocks to show where a block | ||
| * would go if dropped immediately. | ||
| * This is the scratch-blocks equivalent of connection highlighting. |
There was a problem hiding this comment.
remove ref to scratch-blocks.
core/insertion_marker_manager.js
Outdated
| /** | ||
| * Connection on the insertion marker block that corresponds to | ||
| * this.localConnection_ on the currently dragged block. | ||
| * This is part of the scratch-blocks equivalent of connection highlighting. |
There was a problem hiding this comment.
remove scratch-blocks ref.
The basics
The details
Proposed Changes
Add the insertion marker manager class
Mark the dragged connection manager class deprecated, and remove the only use of it
(I propose leaving it in until we have a clear upgrade strategy for developers)
Add utility functions that are called by the insertion marker manager
Reason for Changes
Blockly should have insertion markers! They look snazzy on Scratch Blocks, and the plan was always to backport them to Blockly.
Test Coverage
Unit tests pass.
Tested on:
Additional Information
You can play with this on my demo site for now. I reserve the right to update that site without warning.