-
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
feat: improved insertion flow #455
Conversation
565031a to
2cd4149
Compare
|
'M' then 'Escape' on an existing statement block now moves the cursor between that block and the previous block which is a regression. Even weirder if you move it before cancelling as the connection location is based on where the preview was shown not where it moves back to on cancel. For a value block (e.g. test in |
|
Sorry, will need to take a look at this tomorrow. There's a lot of context that I don't know here that I'll need to familiarize myself with in order to do an effective review. Feel free to redirect to someone who has more context if that's preferable, but otherwise I will take a pass tomorrow (likely in the early afternoon PT). |
microbit-matt-hillsdon
left a comment
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.
Keen to get this one merged. It looks good from my perspective except for the one note I added previously re cancelling a move of a preexisting block. I've added a suggested fix.
@rachel-fenichel there's also your note in the PR description about the lack of need to unpatch the dragger as it's recreated. So that's potentially some easy simplification.
src/actions/mover.ts
Outdated
| info.startLocation, | ||
| ); | ||
|
|
||
| if (target) { |
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.
This seems a straightforward fix for my feedback:
| if (target) { | |
| if (dragStrategy.isNewBlock && target) { |
If we go ahead with removing connection positions then the code in the block will likely need a tweak too, but let's get this in ahead of thinking about that.
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.
Done.
BenHenning
left a comment
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.
Apologies for the delayed review. I had a few comments, but they're largely nits so going ahead and approving.
The solutions make sense to me, though admittedly I don't grok the complete dragging context. :)
| workspace.setResizesEnabled(false); | ||
| Events.setGroup(true); | ||
| const existingGroup = Events.getGroup(); | ||
| if (!existingGroup) { |
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.
src/navigation.ts
Outdated
| * | ||
| * @param stationaryNode The first node to connect. | ||
| * @param movingBlock The block we're moving. | ||
| * @returns True if the key was handled; false if something went |
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 this correct? Seems like it should be tied to whether the connection was successful (per insertBlock's docs), not anything about keys.
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.
| callback: (workspace) => this.mover.startMove(workspace), | ||
| preconditionFn: (workspace) => { | ||
| const startBlock = this.getCurrentBlock(workspace); | ||
| return !!startBlock && this.mover.canMove(workspace, startBlock); |
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.
Why not just startBlock && ...? '!!' seems unnecessary here. Ditto below in a few places.
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.
Needs to return a boolean, not null, and the compiler yelled.
src/actions/move.ts
Outdated
| const curNode = workspace?.getCursor()?.getCurNode(); | ||
| let block = curNode?.getSourceBlock(); | ||
| if (!block) return undefined; | ||
| while (block && block.isShadow()) { |
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.
I'm assuming the truthy check for block here is because TypeScript doesn't realize that it's impossible for it to ever be null or undefined?
If it's null inference is actually good enough to detect that, you should be able to drop that part of the condition.
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.
Done.
src/keyboard_drag_strategy.ts
Outdated
| override startDrag(e?: PointerEvent) { | ||
| if (!this.cursor) throw new Error('precondition failure'); | ||
| // Select and focus block. | ||
| common.setSelected(this.block); |
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.
Won't setCurNode guarantee selection? It'd be nice to consolidate since otherwise every setSelected() needs to be reconsidered for focus.
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.
Removed setSelected
src/keyboard_drag_strategy.ts
Outdated
| ): ConnectionCandidate | null { | ||
| const cursor = draggingBlock.workspace.getCursor(); | ||
| if (!cursor) return null; | ||
| // TODO: Handle the case where the cursor is null, or never return null |
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.
This seems worthwhile to maybe file an issue for and point to it.
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.
Filed #471 and removed the comment here because it's a general problem as described by the issue, this is just an instance of it.
2cd4149 to
cb61c52
Compare
|
@gonfunko please take a look--I fixed the issues Ben identified + accepted Matt's suggested patch. I think the tests failing are the ones that Erik is currently working on/investigating. |
cb61c52 to
ec99e35
Compare
|
Retested manually and with automated tests after RaspberryPiFoundation/blockly#8933 and it still works, so I'm merging now. |
cedde35
into
RaspberryPiFoundation:main
Fixes #421
Based on #438
This is intended to be reviewed one commit at a time; each commit is small.
Behaviour after change
Escapedeletes the newly inserted block.Escapeputs the cursor at the last target connection, (if any).Additional information
This is largely the change that @microbit-matt-hillsdon made, rebased onto main.
I had a grand plan to do all the work to find the
insertStartPointinKeyboardDragStrategyinstead of having to pass it into the drag strategy. That's the reason that I started by passing the block andisNewBlockinto the drag strategy. This idea failed becausegetStationaryNodemust be called before creating the new block, to avoid updating the cursor. I could pass the stationary node into the drag strategy instead of the start point, but in both cases I'm doing layer bypass to move information around. So that was a dud.A few changes:
startMove, instead of expecting the mover to find it by looking at the cursor.startMove.