Skip to content

Commit 39019f6

Browse files
committed
Fix LocalizedLine::text_for_attribute
1 parent a10ada9 commit 39019f6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

crates/bevy_plugin/src/dialogue_runner/localized_line.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ impl LocalizedLine {
130130
// Documentation taken from `YarnLine`
131131
/// Returns the substring of [`YarnLine::text`] covered by the passed `attribute`s [`MarkupAttribute::position`] and [`MarkupAttribute::length`] fields.
132132
pub fn text_for_attribute(&self, attribute: &MarkupAttribute) -> &str {
133-
assert!(
134-
self.text.len() <= attribute.position + attribute.length,
135-
"Attribute \"{attribute}\" represents a range not representable by this text: \"{}\". \
136-
Does this MarkupAttribute belong to this MarkupParseResult?",
137-
self.text
138-
);
139-
&self.text[attribute.position..attribute.position + attribute.length]
133+
self.text
134+
.get(attribute.position..attribute.position + attribute.length)
135+
.unwrap_or_else(|| panic!(
136+
"Attribute \"{attribute}\" represents a range not representable by this text: \"{}\". \
137+
Does this MarkupAttribute belong to this MarkupParseResult?",
138+
self.text
139+
))
140140
}
141141

142142
// Documentation taken from `YarnLine`

0 commit comments

Comments
 (0)