-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix: Improve flyout behavior #9576
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
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0dcdfd2
fix: Don't suppress and re-fire events when dragging blocks from the …
gonfunko f0a2478
fix: Fix bug that could cause blocks to get bumped when dragging from…
gonfunko 79cb632
fix: Fix bug that made it more difficult to drag blocks from scrollab…
gonfunko c57b87e
chore: Run formatter
gonfunko c78f5b4
refactor: Clean up `createBlock`
gonfunko d4c861c
fix: Hide chaff at the end of block creation
gonfunko 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 |
|---|---|---|
|
|
@@ -38,7 +38,6 @@ import * as dom from './utils/dom.js'; | |
| import * as idGenerator from './utils/idgenerator.js'; | ||
| import {Svg} from './utils/svg.js'; | ||
| import * as toolbox from './utils/toolbox.js'; | ||
| import * as Variables from './variables.js'; | ||
| import {WorkspaceSvg} from './workspace_svg.js'; | ||
|
|
||
| /** | ||
|
|
@@ -813,44 +812,16 @@ export abstract class Flyout | |
| * @internal | ||
| */ | ||
| createBlock(originalBlock: BlockSvg): BlockSvg { | ||
| let newBlock = null; | ||
| eventUtils.disable(); | ||
| const variablesBeforeCreation = this.targetWorkspace | ||
| .getVariableMap() | ||
| .getAllVariables(); | ||
| this.targetWorkspace.setResizesEnabled(false); | ||
| try { | ||
| newBlock = this.placeNewBlock(originalBlock); | ||
| return this.placeNewBlock(originalBlock); | ||
| } finally { | ||
| eventUtils.enable(); | ||
| } | ||
|
|
||
| // Close the flyout. | ||
| this.targetWorkspace.hideChaff(); | ||
|
|
||
| const newVariables = Variables.getAddedVariables( | ||
| this.targetWorkspace, | ||
| variablesBeforeCreation, | ||
| ); | ||
| this.targetWorkspace.hideChaff(); | ||
|
|
||
| if (eventUtils.isEnabled()) { | ||
| eventUtils.setGroup(true); | ||
| // Fire a VarCreate event for each (if any) new variable created. | ||
| for (let i = 0; i < newVariables.length; i++) { | ||
| const thisVariable = newVariables[i]; | ||
| eventUtils.fire( | ||
| new (eventUtils.get(EventType.VAR_CREATE))(thisVariable), | ||
| ); | ||
| // Close the flyout. | ||
| if (this.autoClose) { | ||
|
Contributor
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. Doesn't hiding the chaff on the target workspace already close the flyout?
Contributor
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. Indeed it does, this was left over from before, but removed accordingly! |
||
| this.hide(); | ||
| } | ||
|
|
||
| // Block events come after var events, in case they refer to newly created | ||
| // variables. | ||
| eventUtils.fire(new (eventUtils.get(EventType.BLOCK_CREATE))(newBlock)); | ||
| } | ||
| if (this.autoClose) { | ||
| this.hide(); | ||
| } | ||
| return newBlock; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -890,7 +861,9 @@ export abstract class Flyout | |
| const json = this.serializeBlock(oldBlock); | ||
| // Normally this resizes leading to weird jumps. Save it for terminateDrag. | ||
| targetWorkspace.setResizesEnabled(false); | ||
| const block = blocks.append(json, targetWorkspace) as BlockSvg; | ||
| const block = blocks.appendInternal(json, targetWorkspace, { | ||
| recordUndo: true, | ||
| }) as BlockSvg; | ||
|
|
||
| this.positionNewBlock(oldBlock, block); | ||
|
|
||
|
|
||
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.
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.
If the block is not successfully created then now the flyout is closed, where previously the event utils would be enabled but then the method would crash (without closing flyout)
I think if a block isn't ultimately created for whatever reason (not sure how likely this method is to throw an error in reality) it would be better for the flyout not to close.
i don't think you need to use a
tryanymore since we don't have to clean up the event utils. ifplaceNewBlockerrors then just let it error. so you can hideChaff before you return the new block without relying on thefinallyblock.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 catch, updated; this left this method as nothing but
hideChaff()and calling through toplaceNewBlock(), so I inlinedplaceNewBlock()here as it was private and had no other callsites.