-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add constrained movement #384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add constrained movement #384
Conversation
src/keyboard_drag_strategy.ts
Outdated
| /** | ||
| * Returns the next compatible connection in keyboard navigation order, | ||
| * based on the input direction. | ||
| * Always resumes the search at the last |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this comment is cut off
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
| private getConstrainedConnectionCandidate( | ||
| draggingBlock: BlockSvg, | ||
| ): ConnectionCandidate | null { | ||
| const cursor = draggingBlock.workspace.getCursor() as LineCursor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even when line cursor is the default in core, we'll still let people have other types right? can you leave a comment or something to remind us that we'll need to adjust this logic as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a todo and filed an issue.
src/keyboard_drag_strategy.ts
Outdated
| localConns.forEach((conn: RenderedConnection) => { | ||
| const potentialLocation = | ||
| potential?.getLocation() as RenderedConnection; | ||
| if (connectionChecker.canConnect(conn, potentialLocation, true, 5000)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the 5000 here just a really big number? what about Infinity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I forgot Infinity exists. Changed.
Fixes #364
This PR adds constrained movement by selectively extending and overriding parts of the drag strategy. In particular:
searchNodeproperty, which is where a constrained search should start traversing the tree.currCandidateIsBetterto always return false for a constrained drag. That is, the new candidate is always preferred.getConnectionCandidateto callgetConstrainedConnectionCandidateif the movement was constrained.getConstrainedConnectionCandidateimplements the following algorithm:searchNode.Additional information
This does not position the dragging block near the connection (tracked in #370). I'm still figuring out how to do that without causing very weird jumps--I have to push information backwards through the dragging pipeline.
This does not loop from the last block in the workspace to the first, or vice versa (tracked in #369).
When you switch from unconstrained to constrained dragging, the traversal will always resume at the last valid connection that was tried. This may lead to unexpected jumps.
If you use the arrow keys to constrained move off the edge of the workspace, it will not scroll to keep it in view (tracked in #371). The drag will continue and end appropriately on an escape or enter.
I'm accessing a lot of private properties. Every
@ts-expect-erroris a sign of an API problem we need to sort out.