Fix wrong galley split behavior when text ends with new line (#7320)
* Fixes a bug introduced by #7316 The last `\n` was ignored for texts ending with `\n` in the galley split logic.
This commit is contained in:
parent
9fd0ad36e0
commit
087e56abae
|
|
@ -886,9 +886,12 @@ impl GalleyCache {
|
||||||
let is_first_paragraph = start == 0;
|
let is_first_paragraph = start == 0;
|
||||||
// `end` will not include the `\n` since we don't want to create an empty row in our
|
// `end` will not include the `\n` since we don't want to create an empty row in our
|
||||||
// split galley
|
// split galley
|
||||||
let end = job.text[start..]
|
let mut end = job.text[start..]
|
||||||
.find('\n')
|
.find('\n')
|
||||||
.map_or(job.text.len(), |i| start + i);
|
.map_or(job.text.len(), |i| start + i);
|
||||||
|
if end == job.text.len() - 1 && job.text.ends_with('\n') {
|
||||||
|
end += 1; // If the text ends with a newline, we include it in the last paragraph.
|
||||||
|
}
|
||||||
|
|
||||||
let mut paragraph_job = LayoutJob {
|
let mut paragraph_job = LayoutJob {
|
||||||
text: job.text[start..end].to_owned(),
|
text: job.text[start..end].to_owned(),
|
||||||
|
|
@ -1083,6 +1086,12 @@ mod tests {
|
||||||
Color32::WHITE,
|
Color32::WHITE,
|
||||||
f32::INFINITY,
|
f32::INFINITY,
|
||||||
),
|
),
|
||||||
|
LayoutJob::simple(
|
||||||
|
"ends with newlines\n\n".to_owned(),
|
||||||
|
FontId::new(14.0, FontFamily::Monospace),
|
||||||
|
Color32::WHITE,
|
||||||
|
f32::INFINITY,
|
||||||
|
),
|
||||||
LayoutJob::simple(
|
LayoutJob::simple(
|
||||||
"Simple test.".to_owned(),
|
"Simple test.".to_owned(),
|
||||||
FontId::new(14.0, FontFamily::Monospace),
|
FontId::new(14.0, FontFamily::Monospace),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue