Skip to content

Commit 2d0efb1

Browse files
authored
Parley: filter out empty ranges (#9641)
1 parent 01f510f commit 2d0efb1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

internal/core/textlayout/sharedparley.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ impl Default for LayoutOptions {
124124
}
125125
}
126126

127-
fn layout(text: &str, scale_factor: ScaleFactor, options: LayoutOptions) -> Layout {
127+
fn layout(text: &str, scale_factor: ScaleFactor, mut options: LayoutOptions) -> Layout {
128+
// When a piece of text is first selected, it gets an empty range like `Some(1..1)`.
129+
// If the text starts with a multi-byte character then this selection will be within
130+
// that character and parley will panic. We just filter out empty selection ranges.
131+
options.selection = options.selection.filter(|selection| !selection.is_empty());
132+
128133
let max_physical_width = options.max_width.map(|max_width| max_width * scale_factor);
129134
let max_physical_height = options.max_height.map(|max_height| max_height * scale_factor);
130135
let pixel_size = options

0 commit comments

Comments
 (0)