-
Notifications
You must be signed in to change notification settings - Fork 13
fix: remove marked node field #273
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
Closed
microbit-matt-hillsdon
wants to merge
2
commits into
RaspberryPiFoundation:main
from
microbit-matt-hillsdon:simplify-marked-node
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,12 +73,6 @@ export class Navigation { | |
| */ | ||
| protected passiveFocusIndicator: PassiveFocus = new PassiveFocus(); | ||
|
|
||
| /** | ||
| * The node that has passive focus when the cursor has moved to the flyout | ||
| * or toolbox; null if the cursor is moving around the main workspace. | ||
| */ | ||
| protected markedNode: Blockly.ASTNode | null = null; | ||
|
|
||
| /** | ||
| * Constructor for keyboard navigation. | ||
| */ | ||
|
|
@@ -418,9 +412,12 @@ export class Navigation { | |
| if (!toolbox) { | ||
| return; | ||
| } | ||
| const cursor = workspace.getCursor(); | ||
| if (cursor) { | ||
| this.passiveFocusIndicator.show(cursor.getCurNode()); | ||
| cursor.hide(); | ||
| } | ||
|
|
||
| this.markAtCursor(workspace); | ||
| workspace.getCursor()?.hide(); | ||
| this.setState(workspace, Constants.STATE.TOOLBOX); | ||
| this.resetFlyout(workspace, false /* shouldHide */); | ||
|
|
||
|
|
@@ -443,8 +440,11 @@ export class Navigation { | |
| * @param workspace The workspace the flyout is on. | ||
| */ | ||
| focusFlyout(workspace: Blockly.WorkspaceSvg) { | ||
| workspace.getCursor()?.hide(); | ||
| this.markAtCursor(workspace); | ||
| const cursor = workspace.getCursor(); | ||
| if (cursor) { | ||
| this.passiveFocusIndicator.show(cursor.getCurNode()); | ||
| cursor.hide(); | ||
|
Comment on lines
+445
to
+446
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. Does it still work if you call |
||
| } | ||
|
|
||
| const flyout = workspace.getFlyout(); | ||
| this.setState(workspace, Constants.STATE.FLYOUT); | ||
|
|
@@ -482,6 +482,9 @@ export class Navigation { | |
| this.resetFlyout(workspace, reset); | ||
| this.setState(workspace, Constants.STATE.WORKSPACE); | ||
| this.setCursorOnWorkspaceFocus(workspace, keepCursorPosition); | ||
|
|
||
| this.passiveFocusIndicator.hide(); | ||
| workspace.getCursor()?.draw(); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -505,12 +508,6 @@ export class Navigation { | |
| return; | ||
| } | ||
|
|
||
| if (this.markedNode) { | ||
| cursor.setCurNode(this.markedNode); | ||
| this.removeMark(workspace); | ||
| return; | ||
| } | ||
|
|
||
| const disposed = cursor.getCurNode()?.getSourceBlock()?.disposed; | ||
| if (cursor.getCurNode() && !disposed && keepPosition) { | ||
| // Retain the cursor's previous position since it's set, but only if not | ||
|
|
@@ -555,13 +552,14 @@ export class Navigation { | |
| * the block will be placed on. | ||
| */ | ||
| insertFromFlyout(workspace: Blockly.WorkspaceSvg) { | ||
| const stationaryNode = workspace.getCursor()?.getCurNode(); | ||
| const newBlock = this.createNewBlock(workspace); | ||
| if (!newBlock) return; | ||
| if (this.markedNode) { | ||
| if (stationaryNode) { | ||
| if ( | ||
| !this.tryToConnectNodes( | ||
| workspace, | ||
| this.markedNode, | ||
| stationaryNode, | ||
| Blockly.ASTNode.createBlockNode(newBlock)!, | ||
| ) | ||
| ) { | ||
|
|
@@ -575,7 +573,6 @@ export class Navigation { | |
| workspace | ||
| .getCursor()! | ||
| .setCurNode(Blockly.ASTNode.createBlockNode(newBlock)!); | ||
| this.removeMark(workspace); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -628,26 +625,6 @@ export class Navigation { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Connects the location of the marked node and the location of the cursor. | ||
| * No-op if the marked node or cursor node are null. | ||
| * | ||
| * @param workspace The main workspace. | ||
| * @returns True if the cursor and marker locations were connected, | ||
| * false otherwise. | ||
| */ | ||
| connectMarkerAndCursor(workspace: Blockly.WorkspaceSvg): boolean { | ||
| const cursorNode = workspace.getCursor()!.getCurNode(); | ||
|
|
||
| if (this.markedNode && cursorNode) { | ||
| if (this.tryToConnectNodes(workspace, this.markedNode, cursorNode)) { | ||
| this.removeMark(workspace); | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Tries to intelligently connect the blocks or connections | ||
| * represented by the given nodes, based on node types and locations. | ||
|
|
@@ -1082,32 +1059,6 @@ export class Navigation { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Moves the passive focus indicator to the cursor's current location. | ||
| * | ||
| * @param workspace The workspace. | ||
| */ | ||
| markAtCursor(workspace: Blockly.WorkspaceSvg) { | ||
| const cursor = workspace.getCursor()!; | ||
| this.markedNode = cursor.getCurNode(); | ||
|
|
||
| // Although it seems like this should never happen, the typings are wrong | ||
| // in the base Marker class and this can therefore be null. | ||
| if (this.markedNode) { | ||
| this.passiveFocusIndicator.show(this.markedNode); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Removes the passive focus indicator from its current location and hides it. | ||
| * | ||
| * @param workspace The workspace. | ||
| */ | ||
| removeMark(workspace: Blockly.WorkspaceSvg) { | ||
| this.passiveFocusIndicator.hide(); | ||
| this.markedNode = null; | ||
| } | ||
|
|
||
| /** | ||
| * Enables accessibility mode. | ||
| * | ||
|
|
@@ -1135,7 +1086,6 @@ export class Navigation { | |
| workspace.keyboardAccessibilityMode | ||
| ) { | ||
| workspace.keyboardAccessibilityMode = false; | ||
| this.markAtCursor(workspace); | ||
| workspace.getCursor()!.hide(); | ||
| if (this.getFlyoutCursor(workspace)) { | ||
| this.getFlyoutCursor(workspace)!.hide(); | ||
|
|
@@ -1250,7 +1200,6 @@ export class Navigation { | |
| * @param workspace The active workspace. | ||
| */ | ||
| openToolboxOrFlyout(workspace: Blockly.WorkspaceSvg) { | ||
| this.markAtCursor(workspace); | ||
| if (workspace.getToolbox()) { | ||
| this.focusToolbox(workspace); | ||
| } else { | ||
|
|
@@ -1390,7 +1339,6 @@ export class Navigation { | |
| Blockly.ASTNode.createBlockNode(block)!, | ||
| ); | ||
| } | ||
| this.removeMark(workspace); | ||
| return true; | ||
| } | ||
| Blockly.Events.setGroup(false); | ||
|
|
||
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.
It should be noted that (contrary to expectations)
Marker.prototype.hidedoes not cause the cursor to be persistently hidden, but only hides the marker SVG, and only until the next time a render occurs.Marker SVG is used for denoting position of cursor when it is on a connection or on the workspace (or on a whole-stack node, though these are only currently accessible via the context-out shortcut which will probably go away very soon).
So AFAICT this won't hide the cursor if it's on a block, and if it isn't on a block then it will be hidden but may reappear unexpectedly if something causes a render to occur.
Probably not a big deal, given that the existing code does exactly the same thing, though I do wonder if it might be better to hide the cursor before showing the passive focus indicator (here and in
focusFlyout).