refactor: extract editor dom event helpers

This commit is contained in:
lix-2026
2026-05-25 07:23:39 +08:00
parent 82074f410c
commit 7956db06c2
6 changed files with 32 additions and 17 deletions
+1 -16
View File
@@ -39,6 +39,7 @@ use editor_runtime::block_hover_state::{
use editor_runtime::command_sync::{
read_editor_snapshot, sync_editor_outputs, sync_persisted_editor_command,
};
use editor_runtime::dom_events::{event_target_matches_selector, target_element};
use editor_runtime::dom_selection::{
runtime_block_id_from_index, selection_payload, selection_summary, SelectionPayload,
};
@@ -4843,22 +4844,6 @@ fn block_label_for_element(block: &Element) -> String {
}
}
fn target_element(target: web_sys::EventTarget) -> Option<Element> {
target.clone().dyn_into::<Element>().ok().or_else(|| {
target
.dyn_into::<Node>()
.ok()
.and_then(|node| node.parent_element())
})
}
fn event_target_matches_selector(target: Option<web_sys::EventTarget>, selector: &str) -> bool {
target
.and_then(target_element)
.and_then(|element| element.closest(selector).ok().flatten())
.is_some()
}
fn current_target_html_element(event: &WheelEvent) -> Option<HtmlElement> {
event.current_target()?.dyn_into::<HtmlElement>().ok()
}