From 0eea366410b45d8b427895b4abd319be3f86d3d3 Mon Sep 17 00:00:00 2001 From: Mohammad AlSaleh Date: Thu, 11 Jan 2024 02:31:28 +0300 Subject: [PATCH] =?UTF-8?q?Add=20LEFT=E2=80=91TO=E2=80=91RIGHT=20ISOLATE?= =?UTF-8?q?=20character=20to=20the=20beginning=20of=20lines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This zero-width char will force the shaper to treat detected RTL lines as LTR. RTL text would still be rendered correctly. But this fixes the wrong behavior of it being displayed aligned to the right. Signed-off-by: Mohammad AlSaleh --- src/terminal.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/terminal.rs b/src/terminal.rs index cbb628a..d700af2 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -433,6 +433,12 @@ impl Terminal { } pub fn update(&mut self) -> bool { + // LEFT‑TO‑RIGHT ISOLATE character. + // This will be added to the beginning of lines to force the shaper to treat detected RTL + // lines as LTR. RTL text would still be rendered correctly. But this fixes the wrong + // behavior of it being aligned to the right. + const LRI:char = '\u{2066}'; + let instant = Instant::now(); //TODO: is redraw needed after all events? @@ -442,7 +448,7 @@ impl Terminal { let mut line_i = 0; let mut last_point = None; - let mut text = String::new(); + let mut text = String::from(LRI); let mut attrs_list = AttrsList::new(self.default_attrs); { let term = self.term.lock(); @@ -464,6 +470,7 @@ impl Terminal { line_i += 1; text.clear(); + text.push(LRI); attrs_list.clear_spans(); } //TODO: use indexed.point.column?