`wrap_line` returns breakpoints relative to how we sliced the text, so we need to break things appropriately.

This prevents a bounds-check panic when we inevitably try to slice an array like `[300..2]` or something like that.

We also skip rendering the space that we're turning into a newline to avoid it popping up on the next line by accident.
This commit is contained in:
David Wendt 2020-05-22 23:40:39 -04:00
parent ece879a15c
commit cb47e0bae8
1 changed files with 7 additions and 4 deletions

View File

@ -350,21 +350,24 @@ impl<'gc> LayoutBox<'gc> {
while let Some(breakpoint) =
font.wrap_line(&text[last_breakpoint..], font_size, width, offset)
{
if breakpoint == last_breakpoint {
if breakpoint == 0 {
layout_context.newline(context.gc_context);
last_breakpoint += 1;
continue;
}
let next_breakpoint = last_breakpoint + breakpoint;
Self::append_text_fragment(
context.gc_context,
&mut layout_context,
&text[last_breakpoint..breakpoint],
&text[last_breakpoint..next_breakpoint],
start + last_breakpoint,
start + breakpoint,
start + next_breakpoint,
span,
);
last_breakpoint = breakpoint;
last_breakpoint = next_breakpoint + 1;
if last_breakpoint >= text.len() {
break;
}