-
Notifications
You must be signed in to change notification settings - Fork 13
feat: improved insertion flow #455
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
Merged
rachel-fenichel
merged 12 commits into
RaspberryPiFoundation:main
from
rachel-fenichel:clean-insert-then-move
Apr 25, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e02058a
refactor: create findInsertStartPoint
rachel-fenichel 80ba31a
refactor: pass Navigation into the keyboard drag strategy
rachel-fenichel ee73e71
refactor: pass block into startMove
rachel-fenichel ea28013
refactor: set selected and curNode in startDrag
rachel-fenichel 1d73f80
feat: wire isNewBlock into keyboard drag strategy
rachel-fenichel 1923d3c
feat: monkeypatch dragger as needed to delete on aborted insertion
rachel-fenichel 246a14d
feat: pass insertStartPoint into the drag strategy after all
rachel-fenichel 8654f66
feat: make insertion wrap a block immediately
rachel-fenichel a25cebe
fix: undo deletes the newly insertedblock
rachel-fenichel 44bc613
fix: reference to getCurrentBlock
rachel-fenichel 67fd4c2
chore: fix review feedback
rachel-fenichel ec99e35
chore: remove unnecessary unpatch method
rachel-fenichel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| */ | ||
|
|
||
| import { | ||
| BlockSvg, | ||
| ContextMenuRegistry, | ||
| ShortcutRegistry, | ||
| utils, | ||
|
|
@@ -28,8 +29,16 @@ export class MoveActions { | |
| // Begin and end move. | ||
| { | ||
| name: 'Start move', | ||
| preconditionFn: (workspace) => this.mover.canMove(workspace), | ||
| callback: (workspace) => this.mover.startMove(workspace), | ||
| preconditionFn: (workspace) => { | ||
| const startBlock = this.getCurrentBlock(workspace); | ||
| return !!startBlock && this.mover.canMove(workspace, startBlock); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs to return a boolean, not null, and the compiler yelled. |
||
| }, | ||
| callback: (workspace) => { | ||
| const startBlock = this.getCurrentBlock(workspace); | ||
| return ( | ||
| !!startBlock && this.mover.startMove(workspace, startBlock, null) | ||
| ); | ||
| }, | ||
| keyCodes: [KeyCodes.M], | ||
| }, | ||
| { | ||
|
|
@@ -131,12 +140,19 @@ export class MoveActions { | |
| const workspace = scope.block?.workspace as WorkspaceSvg | null; | ||
| if (!workspace || menuOpenEvent instanceof PointerEvent) | ||
| return 'hidden'; | ||
| return this.mover.canMove(workspace) ? 'enabled' : 'disabled'; | ||
|
|
||
| const startBlock = this.getCurrentBlock(workspace); | ||
| return !!startBlock && this.mover.canMove(workspace, startBlock) | ||
| ? 'enabled' | ||
| : 'disabled'; | ||
| }, | ||
| callback: (scope) => { | ||
| const workspace = scope.block?.workspace as WorkspaceSvg | null; | ||
| if (!workspace) return false; | ||
| this.mover.startMove(workspace); | ||
| const startBlock = this.getCurrentBlock(workspace); | ||
| return ( | ||
| !!startBlock && this.mover.startMove(workspace, startBlock, null) | ||
| ); | ||
| }, | ||
| scopeType: ContextMenuRegistry.ScopeType.BLOCK, | ||
| id: 'move', | ||
|
|
@@ -168,4 +184,30 @@ export class MoveActions { | |
| ContextMenuRegistry.registry.unregister(menuItem.id); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get the source block for the cursor location, or undefined if no | ||
| * source block can be found. | ||
| * If the cursor is on a shadow block, walks up the tree until it finds | ||
| * a non-shadow block to drag. | ||
| * | ||
| * @param workspace The workspace to inspect for a cursor. | ||
| * @returns The source block, or undefined if no appropriate block | ||
| * could be found. | ||
| */ | ||
| getCurrentBlock(workspace: WorkspaceSvg): BlockSvg | undefined { | ||
| const curNode = workspace?.getCursor()?.getCurNode(); | ||
| let block = curNode?.getSourceBlock(); | ||
| if (!block) return undefined; | ||
| while (block?.isShadow()) { | ||
| block = block.getParent(); | ||
| if (!block) { | ||
| throw new Error( | ||
| 'Tried to drag a shadow block with no parent. ' + | ||
| 'Shadow blocks should always have parents.', | ||
| ); | ||
| } | ||
| } | ||
| return block as BlockSvg; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe add a line comment here explaining why this is important (otherwise the context feels maybe a bit hidden).
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 short comment. This is also a pattern in all of Blockly.