Fix panic when copying smart quotes in MarkdownElement (#29285)

Release Notes:

- Fixed a panic that could sometimes happen when copying text in the
agent.
This commit is contained in:
Antonio Scandurra 2025-04-23 17:17:27 +02:00 committed by GitHub
parent a320d324f1
commit 09db31288a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 123 additions and 10 deletions

View file

@ -278,6 +278,7 @@ impl IntoElement for StyledText {
pub struct TextLayout(Rc<RefCell<Option<TextLayoutInner>>>);
struct TextLayoutInner {
len: usize,
lines: SmallVec<[WrappedLine; 1]>,
line_height: Pixels,
wrap_width: Option<Pixels>,
@ -349,6 +350,7 @@ impl TextLayout {
} else {
text.clone()
};
let len = text.len();
let Some(lines) = window
.text_system()
@ -363,6 +365,7 @@ impl TextLayout {
else {
element_state.0.borrow_mut().replace(TextLayoutInner {
lines: Default::default(),
len: 0,
line_height,
wrap_width,
size: Some(Size::default()),
@ -380,6 +383,7 @@ impl TextLayout {
element_state.0.borrow_mut().replace(TextLayoutInner {
lines,
len,
line_height,
wrap_width,
size: Some(size),
@ -544,6 +548,11 @@ impl TextLayout {
self.0.borrow().as_ref().unwrap().line_height
}
/// The UTF-8 length of the underlying text.
pub fn len(&self) -> usize {
self.0.borrow().as_ref().unwrap().len
}
/// The text for this layout.
pub fn text(&self) -> String {
self.0