Skip to content
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

Readonly disappears forever if window is resized while not readonly #78

Closed
markfinn opened this issue Feb 11, 2022 · 4 comments · Fixed by #87
Closed

Readonly disappears forever if window is resized while not readonly #78

markfinn opened this issue Feb 11, 2022 · 4 comments · Fixed by #87

Comments

@markfinn
Copy link
Contributor

If anything calls Blockly.svgResize while readonly is false you will never see the readonly workspace again unless you call Blockly.svgResize again. Blockly.svgResize is called a lot in my code for dynamic reflows, but it's also easy to trigger in NGX-Blockly itself by resizing the browser window.

The cause is that when the secondaryContainer div is hidden it will report a size of 0x0 and Blockly.svgResize will smash the blockly workspace down to that invisible size. That's fine while hidden, but when you un-hide, the SVG workspace is still 0x0. The fix is to call svgResize after removing the hidden class from secondaryContainer:

     public setReadonly(readOnly: boolean) {
         this.readOnly = readOnly;
         if (readOnly) {
             this.secondaryContainer.nativeElement.classList.remove('hidden');
             if (!this._secondaryWorkspace) {
                 const config = {...this.config};
                 config.readOnly = true;
                 this._secondaryWorkspace = Blockly.inject(this.secondaryContainer.nativeElement, config);
             }
             Blockly.Xml.clearWorkspaceAndLoadFromXml(Blockly.Xml.textToDom(this.toXml()), this._secondaryWorkspace);
+            Blockly.svgResize(this._secondaryWorkspace);
         } else {
             if (this._secondaryWorkspace) {
                 this.secondaryContainer.nativeElement.classList.add('hidden');

Note that this fix alone actually doesn't work yet because of a Blockly issue but I have a fix requested over there too. At the moment I have both this change and that one monkey-patched in and everything works as expected when the widows is resized in either state.

Thanks!

@stale
Copy link

stale bot commented Mar 14, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Mar 14, 2022
@markfinn
Copy link
Contributor Author

Bump to keep from being stale.

@stale stale bot removed the wontfix This will not be worked on label Mar 14, 2022
@markfinn
Copy link
Contributor Author

the fix to blockly is merged at google/blockly#5997, just need this half.

@markfinn
Copy link
Contributor Author

markfinn commented Apr 8, 2022

bump to keep from being stale.

markfinn added a commit to markfinn/ngx-blockly that referenced this issue Apr 8, 2022
…never see the readonly workspace again unless you call Blockly.svgResize again. fixes roroettg#78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant