blockly: real time code generation incorrect while dragging?
Problem statement
It can reproduce with the online demo at: https://developers.google.com/blockly/ While dragging a block from toolbox, the real time generation of code is incorrect.
Expected Behavior
N/A
Actual Behavior
Steps to Reproduce
- open ‘https://developers.google.com/blockly/’
- use the “Try Blockly”
- switch “Language” to “Python” (also fail with other language in fact…).
- drag “if do” block in “logic”
- while dragging, the generated code is as below:
if False:
pass
if False:
pass
which is incorrect and confusing to user. 6. stop dragging and put the block in workspace, the generated code is as below:
if False:
pass
which is correct.
Stack Traces
N/A
Operating System and Browser
Mac OSX, Chrome
Additional Information
N/A
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 15 (4 by maintainers)
What’s the best way to implement a quick fix for those using compressed blockly?
@BeksOmega good observation. I think that should work, though I will need to see tests to be certain.
Another option is to return the empty string from workspace to code if mid-drag, but I can’t imagine that being good for existing uses. (Admittedly, neither is generating bad code, so maybe it’s an acceptable solution if you can’t get yours to work.)
@BeksOmega The Blockly Games Movie solution isn’t general-purpose, it’s relying on the fact that we generate code upon every non-UI change to the workspace (real-time code generation). So the latest PR adds a cache; if we are dragging, use the cache, if no drag generate code and save in the cache. That way valid code is always available.
Lines 384 to 389 here is the check, plus the rest of the PR to handle the cache consistently across all games: https://github.com/google/blockly-games/commit/c4fa71e631d6fc51c5a4c58f82d23b6a9585475d#diff-0ad1ed0ee72ff2f4b4f08c6d7698bedc