Skip to content

Commit

Permalink
Add a workaround for the crash
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab committed Nov 28, 2024
1 parent e714287 commit e5c0752
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions masonry/src/text/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ where
selection: Default::default(),
width: None,
scale: 1.0,
layout_dirty: false,
layout_dirty: true,
alignment: Alignment::Start,
// We don't use the `default` value to start with, as our consumers
// will choose to use that as their initial value, but will probably need
Expand Down Expand Up @@ -630,7 +630,9 @@ where
/// Set the width of the layout.
// TODO: If this is infinite, is the width used for alignnment the min width?
pub fn set_width(&mut self, width: Option<f32>) {
self.width = width;
// Don't allow empty widths:
// https://github.com/linebender/parley/issues/186
self.width = width.map(|width| if width > 10. { width } else { 10. });
self.layout_dirty = true;
}

Expand Down Expand Up @@ -665,7 +667,7 @@ where
for prop in self.default_style.inner().values() {
builder.push_default(prop.to_owned());
}
builder.build_into(&mut self.layout, &self.buffer);
self.layout = builder.build(&self.buffer);
self.layout.break_all_lines(self.width);
self.layout.align(self.width, self.alignment);
self.selection = self.selection.refresh(&self.layout);
Expand Down
8 changes: 4 additions & 4 deletions masonry/src/widget/text_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ impl<const EDITABLE: bool> TextArea<EDITABLE> {
/// To change the font size, use `with_style`, setting [`StyleProperty::FontSize`](parley::StyleProperty::FontSize).
pub fn new(mut text: &str) -> Self {
let mut editor = PlainEditor::new(theme::TEXT_SIZE_NORMAL);
// HACK: Parley crashes if the *initial* text is empty; any subsequent version seems to be fine.
if text.is_empty() {
text = " ";
}
// // HACK: Parley crashes if the *initial* text is empty; any subsequent version seems to be fine.
// if text.is_empty() {
// text = " ";
// }
editor.set_text(text);
TextArea {
editor,
Expand Down

0 comments on commit e5c0752

Please sign in to comment.