refactor: extract hovered block index helper

This commit is contained in:
lix-2026
2026-05-25 07:00:53 +08:00
parent 4eda7179cc
commit 08f9d94d8f
6 changed files with 51 additions and 31 deletions
@@ -95,6 +95,18 @@ pub(crate) fn direct_block_from_element(mut element: Element, root: &Element) ->
}
}
pub(crate) fn direct_block_index_from_element(
element: &Element,
root: &Element,
handle_selector: &str,
) -> Option<usize> {
if element_within_handle_shell(element, handle_selector) {
return None;
}
let block = direct_block_from_element(element.clone(), root)?;
top_level_block_index(root, &block)
}
pub(crate) fn top_level_block_index(root: &Element, block: &Element) -> Option<usize> {
let children = root.children();
(0..children.length()).find_map(|index| {