feat: Insert blocks at focus point#9806
Conversation
mikeharv
left a comment
There was a problem hiding this comment.
Pulled and tested. Seems to work great!
|
|
||
| // If the passively focused node is a connection, return it if it is | ||
| // compatible with the dragged block. | ||
| if (passiveBlockConnections.includes(passiveNode as any)) { |
There was a problem hiding this comment.
Could we check whether passiveNode instanceof RenderedConnection instead of casting as any? At that point, I think we'd also be able to safely infer that it's one of passiveBlockConnection because they have same source block.
There was a problem hiding this comment.
That's not the purpose for the cast, passiveBlockConnections is an array of RenderedConnection, so if it includes passiveNode, we know it is one; unfortunately without this, TS whinges that "Argument of type 'IFocusableNode' is not assignable to parameter of type 'RenderedConnection'.", stubbornly refusing to consider the possibility that the IFocusableNode passiveNode may in fact be a RenderedConnection (which implements IFocusableNode!). Since this is all verifiably safe I just casted to any to satisfy the compiler; doing an instanceof requires a full import of RenderedConnection, and IIRC that leads to an import cycle.
There was a problem hiding this comment.
Ah, got it! I think that's totally reasonable then.
The basics
The details
Resolves
Fixes #9758
Proposed Changes
This PR reintroduces support for inserting blocks from the flyout at or near the currently focused node in the workspace. If a connection is focused, and the chosen block can connect to it, it will be initially moved to/proposed for connection at that point; otherwise, the focused node's parent block will be identified, and, assuming there is one, the inserted block will be proposed for connection to the first compatible connection on that block. A final attempt will be made to connect the inserted block to the focused block's parent block's input connection, after which the inserted block will just be initially proposed as a top-level block.