use crate::renderer::render_tree::{RenderNode, RenderNodeType};
pub(super) fn number_right(node: &RenderNode, marker: &str) -> Option<f64> {
if marker.is_empty() {
return None;
}
let own = match &node.node_type {
RenderNodeType::TextRun(run) => {
let display = run.display_or_text();
display.find(marker).and_then(|offset| {
if !display[..offset].chars().all(char::is_whitespace) {
return None;
}
let end = display[..offset + marker.len()].chars().count();
run.replay_positions_for(display)
.get(end)
.copied()
.map(|advance| node.bbox.x + advance)
.filter(|right| right.is_finite())
})
}
_ => None,
};
node.children
.iter()
.filter_map(|child| number_right(child, marker))
.chain(own)
.reduce(f64::max)
}