avm2: Fix TextField.getLineText()

This patch makes the implementation more performant, simpler, and
fixes its behavior related to returning the line delimiter and tabs.
This commit is contained in:
Kamil Jarosz 2024-06-27 15:23:15 +02:00 committed by Nathan Adams
parent 4f457da07b
commit b55d4d1021
1 changed files with 2 additions and 12 deletions

View File

@ -1920,18 +1920,8 @@ impl<'gc> EditText<'gc> {
pub fn line_text(self, line: usize) -> Option<WString> { pub fn line_text(self, line: usize) -> Option<WString> {
let read = self.0.read(); let read = self.0.read();
let line = read.layout.lines().get(line)?; let line = read.layout.lines().get(line)?;
let text = read.text_spans.text(); let line_text = read.text_spans.text().slice(line.text_range())?;
Some(WString::from_wstr(line_text))
let mut line_text = WString::new();
for layout_box in line.boxes_iter() {
if let LayoutContent::Text { start, end, .. } = layout_box.content() {
if let Some(box_tex) = text.slice(*start..*end) {
line_text.push_str(box_tex);
}
}
}
Some(line_text)
} }
pub fn line_offset(self, line: usize) -> Option<usize> { pub fn line_offset(self, line: usize) -> Option<usize> {