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

MultilineInput - Not sized properly when workspace is loaded. #6071

Closed
nanhishweta-26 opened this issue Apr 11, 2022 · 7 comments
Closed

MultilineInput - Not sized properly when workspace is loaded. #6071

nanhishweta-26 opened this issue Apr 11, 2022 · 7 comments
Labels
component: fields issue: bug Describes why the code or behaviour is wrong needs more info Waiting for developer response

Comments

@nanhishweta-26
Copy link

Hi Team,

As shown in the below screenshots, when the Workspace is cleared and loaded

Multiline block is not sized properly to show all the text within the block as seen in Image1.

But, if we try to edit the block the multiline block is resized to accommodate the text as seen in Image 2. Also, afterwards it retains the size.

Image 1:
image

Image 2:
image

Any help is much appreciated.

Thanks,
Shweta

@nanhishweta-26 nanhishweta-26 added the issue: triage Issues awaiting triage by a Blockly team member label Apr 11, 2022
@maribethb
Copy link
Contributor

Hi, I'm not able to reproduce this. Can you provide more detailed reproduction steps? How are you clearing and reloading the workspace?

Thanks!

@maribethb maribethb added issue: bug Describes why the code or behaviour is wrong component: fields needs more info Waiting for developer response and removed issue: triage Issues awaiting triage by a Blockly team member labels Apr 16, 2022
@maribethb maribethb added this to the Bug Bash Backlog milestone Apr 16, 2022
@nanhishweta-26
Copy link
Author

This is the code to reproduce the bug. Please review and let us know if you need any more details.

`blocklyWorkspace.clear();

var workspaceJSONValue =
{
"blocks": {
"languageVersion": 0,
"blocks": [
{
"type": "modify_form",
"id": "4PMzIgAFVO2s_-m?$:1d",
"x": 10,
"y": 10,
"inputs": {
"modify_form": {
"block": {
"type": "variables_set",
"id": "ud4J|#g9tWCPdL?gO,(K",
"fields": {
"VAR": {
"id": "zFF)Ar@[ZdrIxEL}n)Ao"
}
},
"inputs": {
"VALUE": {
"block": {
"type": "text_multiline",
"id": "|YCm`eZO3k?7g/dw0hb(",
"fields": {
"TEXT": "This is a very long message"
}
}
}
}
}
}
}
}
]
},
"variables": [
{
"name": "Message",
"id": "zFF)Ar@[ZdrIxEL}n)Ao"
}
]
}

Blockly.serialization.workspaces.load(workspaceJSONValue, blocklyWorkspace);`

@Juliandebruin
Copy link

Juliandebruin commented Jul 18, 2022

Is there a workaround for now? I am having the same issue.

@shals1031
Copy link

Hi Blockly team

Even we are facing the same issue in our environment, any plans as to when this fix can be provided or do we any work around for the same.
Expecting as always quick response from your side

@ionous
Copy link

ionous commented Sep 2, 2022

I've encountered this on Windows 10 using Chrome 104.0.5112.102, Firefox 104.0.1, and Edge 104.0.1293.70.

The reason is that textElement.getComputedTextLength() in Blockly.utils.dom.getTextWidth() called by Blockly.FieldMultilineInput.updateSize_() returns 0 because the svg element isn't rendered yet ( Node.isConnected is still false )

re: bugzilla "SVGTextElement.getComputedTextLength() returns 0 if element not rendered" and "SVG display:none rules"

To work around, i derived my own class based on Blockly.FieldMultilineInput, duplicated the updateSize_() implementation, and changed the dom.getTextWidth() call to dom.getFastTextWidth() like the "isBeingEdited_" section uses.

before:
image

after:
image

I don't know what the actual correct fix is though.

[ eta ]

using only getFastTextWidth can cause the text area edit widget to wrap too early. the fast width winds up just a bit smaller than when getTextWidth is valid ( in my case: 467.179... vs 467.395... )

image

changing the line from
const textWidth = dom.getTextWidth(tspan);
to:
const textWidth = dom.getTextWidth(tspan) || dom.getFastTextWidth(tspan, fontSize, fontWeight, fontFamily);

seems to keep the initial text looking good while also keeping the editor wrapping right.

image

@Juliandebruin
Copy link

Juliandebruin commented Sep 3, 2022

Thank you @ionous this fixed my problem. In my case dom of dom.getFastTextWidth was undefined so the solution is to use Blockly.utils.dom.getFastTextWidth which is the alias given in the documentation.

@BeksOmega
Copy link
Collaborator

Fixed by #6461

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: fields issue: bug Describes why the code or behaviour is wrong needs more info Waiting for developer response
Projects
None yet
Development

No branches or pull requests

6 participants