Skip to content

Commit

Permalink
text: Refactor EditText.line_text
Browse files Browse the repository at this point in the history
This refactor takes advantage of the
new layout structure to simplify code.
  • Loading branch information
kjarosh authored and Dinnerbone committed Jun 21, 2024
1 parent bfbd2db commit adea7ae
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions core/src/display_object/edit_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1916,23 +1916,18 @@ impl<'gc> EditText<'gc> {
pub fn line_text(self, line: usize) -> Option<WString> {
let read = self.0.read();
let line = read.layout.lines().get(line)?;
let text = read.text_spans.text();

let mut text = WString::new();
for layout_box in read.layout.boxes_iter() {
if layout_box.bounds().offset_y() < line.offset()
|| layout_box.bounds().extent_y() > line.extent()
{
continue;
}

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) = read.text_spans.text().slice(*start..*end) {
text.push_str(box_tex);
if let Some(box_tex) = text.slice(*start..*end) {
line_text.push_str(box_tex);
}
}
}

Some(text)
Some(line_text)
}

fn execute_avm1_asfunction(
Expand Down

0 comments on commit adea7ae

Please sign in to comment.