google / blockly

The web-based visual programming editor.
https://developers.google.com/blockly/
Apache License 2.0
12.51k stars 3.72k forks source link

Inconsistent RTL text display in dropdown field #8645

Open mikeharv opened 2 weeks ago

mikeharv commented 2 weeks ago

Check for duplicates

Description

When displaying right-to-left (RTL) text in dropdown fields, Blockly currently uses the Right-to-Left Mark (RLM, U+200F) to suggest RTL directionality. However, this approach leads to inconsistent RTL alignment, as the RLM only hints at RTL layout rather than enforcing it across the entire text.

We found that using the Right-to-Left Override (RLO, U+202E) followed by Pop Directional Formatting (PDF, U+202C) produces a more consistent RTL display by enforcing RTL direction for the entire text. The PDF resets the directional formatting after the text, keeping the override localized to the specific field.

Replacing RLM with RLO+PDF ensures the full text displays in a coherent RTL layout, improving readability and alignment when the container is not styled for RTL. We've made that fix in our field override here: https://github.com/code-dot-org/code-dot-org/pull/62232/commits/f73cc9565cfc423ba6c29dbef1394db83120ec2d

This bug feels similar to one affecting number fields that was reported several years ago: https://github.com/google/blockly/issues/1802

Reproduction steps

  1. From the RTL Blockly Playground, open the Logic toolbox category and drag a true block to the workspace.
  2. Using the console, add an option to the dropdown that includes a mix of RTL characters and Latin characters (e.g.) numbers. For example: Blockly.getSelected().getField('BOOL').menuGenerator_.push(["1 תיבה", "TEXT"]).
  3. Observe the inconsistency between the text in the dropdown menu (an RTL element) and the block field (an LTR element).

Stack trace

No response

Screenshots

Image

Browsers

No response

rachel-fenichel commented 1 week ago

RLO + PDF sounds good to me--thanks for the explanation of the change. We will accept an upstream PR fixing this, if you file one.

It sounds like you have tested this in RTL, particularly with Arabic. Do you know if this changes anything for the math examples given in #1802?