Repository navigation
fix: keep right-to-left display text in logical order when it leaves the screen #3286
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
jgregoriorincon
merged 8 commits into
opengeos:main
from
jgregoriorincon:fix/3278-rtl-display-text
Nov 29, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
56f4153
fix: keep right-to-left display text in logical order when it leaves …
jgregoriorincon 96ee099
fix(ui): tidy the display helper and its output test
jgregoriorincon 51bb006
fix(ui): paint data kept in logical order, and reorder only paired marks
jgregoriorincon 388a442
fix(ui): leave text fields and unpaired marks as they are in the pain…
jgregoriorincon 52e6f90
Merge remote-tracking branch 'upstream/main' into fix/3278-rtl-displa…
jgregoriorincon efc9946
fix(ui): keep command data as painted, and drop the paint pass
jgregoriorincon cf2b805
Merge remote-tracking branch 'upstream/main' into fix/3278-rtl-displa…
jgregoriorincon 568b8e0
fix(ui): take the display marks out of a queued plugin command
jgregoriorincon 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 |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| //! The marks right-to-left display text carries. An interface that lays a line out back to | ||
| //! front rewrites it for painting (`ui-egui`'s `i18n::rtl`) and marks what it rewrote, so that | ||
| //! text leaving the screen (a notice, a file name, the clipboard) can be put back in logical | ||
| //! order ([`logical`]), and text kept to be painted as it is (a command's parameters) can lose | ||
| //! the marks alone ([`unmarked`]). | ||
|
|
||
| // Invisible, of no width and no direction. A start and an end differ, so that a mark with no | ||
| // partner, cut from its pair or part of the data, is told apart and left where it is. | ||
|
|
||
| /// Before a rewritten line. | ||
| pub const LINE_START: char = '\u{2063}'; | ||
| /// After a rewritten line. | ||
| pub const LINE_END: char = '\u{2062}'; | ||
| /// Before a run of characters reversed within a rewritten line. | ||
| pub const RUN_START: char = '\u{2064}'; | ||
| /// After such a run. | ||
| pub const RUN_END: char = '\u{2061}'; | ||
| /// Every mark. | ||
| pub const MARKS: [char; 4] = [LINE_START, LINE_END, RUN_START, RUN_END]; | ||
|
|
||
| /// The mirrored glyph of a bracket, which the shaper mirrors back on a back-to-front line. | ||
| #[must_use] | ||
| pub fn mirror(c: char) -> char { | ||
| match c { | ||
| '(' => ')', | ||
| ')' => '(', | ||
| '[' => ']', | ||
| ']' => '[', | ||
| '{' => '}', | ||
| '}' => '{', | ||
| '«' => '»', | ||
| '»' => '«', | ||
| '‹' => '›', | ||
| '›' => '‹', | ||
| c => c, | ||
| } | ||
| } | ||
|
|
||
| /// `shown` with what was rewritten for display put back in logical order, and the marks | ||
| /// around it gone; `None` when no line holds a start mark and its end. Only what stands between | ||
| /// the two is reordered; text around it, and a mark with no partner, stay as they are. | ||
| #[must_use] | ||
| pub fn logical(shown: &str) -> Option<String> { | ||
| unmark(shown, true) | ||
| } | ||
|
|
||
| /// `shown` without the marks [`logical`] would read, its characters left where they are: a | ||
| /// display form kept as data that is painted as it is. `None` when no line holds a pair. | ||
| #[must_use] | ||
| pub fn unmarked(shown: &str) -> Option<String> { | ||
| unmark(shown, false) | ||
| } | ||
|
|
||
| /// [`logical`] when `reorder`, else [`unmarked`]. | ||
| fn unmark(shown: &str, reorder: bool) -> Option<String> { | ||
| if !shown.contains(MARKS) { | ||
| return None; | ||
| } | ||
| let text = shown.split('\n').map(|line| unmark_line(line, reorder)).collect::<Vec<_>>().join("\n"); | ||
| (text != shown).then_some(text) | ||
| } | ||
|
|
||
| /// One line of [`unmark`]. | ||
| fn unmark_line(line: &str, reorder: bool) -> String { | ||
| let chars: Vec<char> = line.chars().collect(); | ||
|
jgregoriorincon marked this conversation as resolved.
Resolved
|
||
| let lines = Pairs::of(&chars, LINE_START, LINE_END); | ||
| let runs = Pairs::of(&chars, RUN_START, RUN_END); | ||
| let mut out = String::with_capacity(line.len()); | ||
| let mut run: Vec<char> = Vec::new(); | ||
| let marks = lines.mark.into_iter().zip(runs.mark).map(|(a, b)| a || b); | ||
| for (((c, mark), in_line), in_run) in chars.into_iter().zip(marks).zip(lines.inside).zip(runs.inside) { | ||
| if reorder && in_run && !mark { | ||
| run.push(mirror(c)); | ||
| continue; | ||
| } | ||
| out.extend(run.drain(..).rev()); | ||
| if !mark { | ||
|
jgregoriorincon marked this conversation as resolved.
Resolved
|
||
| out.push(if reorder && in_line { mirror(c) } else { c }); | ||
| } | ||
| } | ||
| out.extend(run.drain(..).rev()); | ||
| out | ||
| } | ||
|
|
||
| /// Where the complete pairs of one start and end mark are in a line, character by character. | ||
| struct Pairs { | ||
| /// Whether it stands between a start and the end that closes it, both included. | ||
| inside: Vec<bool>, | ||
| /// Whether it is one of those two marks. | ||
| mark: Vec<bool>, | ||
| } | ||
|
|
||
| impl Pairs { | ||
| fn of(chars: &[char], start: char, end: char) -> Self { | ||
| let mut pairs = Self { inside: vec![false; chars.len()], mark: vec![false; chars.len()] }; | ||
| let mut open = None; | ||
| for (i, c) in chars.iter().enumerate() { | ||
| if *c == start { | ||
| open = Some(i); | ||
| } else if *c == end | ||
| && let Some(from) = open.take() | ||
| { | ||
| if let Some(span) = pairs.inside.get_mut(from..=i) { | ||
| span.fill(true); | ||
| } | ||
| for at in [from, i] { | ||
| if let Some(mark) = pairs.mark.get_mut(at) { | ||
| *mark = true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| pairs | ||
| } | ||
| } | ||
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
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
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
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
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.
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.
Uh oh!
There was an error while loading. Please reload this page.