gpui: Fix CJK line wrap for GPUI text render (#17737)

Release Notes:

- N/A

This changes is going to let GPUI render correct text wrapping for CJK
characters. We was done this in PR #11296 for Editor, but this is also
need support for other text renders.

| Before | After |
| --- | --- |
| <img width="488" alt="SCR-20240912-jtvo"
src="https://github.com/user-attachments/assets/d061669c-62ab-4a7e-a724-2df84815d1ed">
| <img width="438" alt="image"
src="https://github.com/user-attachments/assets/ec27fd80-69db-48b6-8ade-694cd65d1843">
|
This commit is contained in:
Jason Lee 2024-09-13 03:55:03 +08:00 committed by GitHub
parent b9b62842f8
commit ee96d69e37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 4 deletions

View file

@ -9,6 +9,8 @@ use std::{
sync::Arc,
};
use super::LineWrapper;
/// A laid out and styled line of text
#[derive(Default, Debug)]
pub struct LineLayout {
@ -152,9 +154,18 @@ impl LineLayout {
continue;
}
if prev_ch == ' ' && ch != ' ' && first_non_whitespace_ix.is_some() {
last_candidate_ix = Some(boundary);
last_candidate_x = x;
// Here is very similar to `LineWrapper::wrap_line` to determine text wrapping,
// but there are some differences, so we have to duplicate the code here.
if LineWrapper::is_word_char(ch) {
if prev_ch == ' ' && ch != ' ' && first_non_whitespace_ix.is_some() {
last_candidate_ix = Some(boundary);
last_candidate_x = x;
}
} else {
if ch != ' ' && first_non_whitespace_ix.is_some() {
last_candidate_ix = Some(boundary);
last_candidate_x = x;
}
}
if ch != ' ' && first_non_whitespace_ix.is_none() {