refactor: extract hovered block index helper
This commit is contained in:
+6
-6
@@ -1270,7 +1270,7 @@ function __wbg_get_imports() {
|
||||
},
|
||||
__wbindgen_cast_0000000000000003: function(arg0, arg1) {
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 973, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
|
||||
const ret = makeClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hdac387fb9e511e9c);
|
||||
const ret = makeClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__had771ddc65647798);
|
||||
return ret;
|
||||
},
|
||||
__wbindgen_cast_0000000000000004: function(arg0, arg1) {
|
||||
@@ -1285,7 +1285,7 @@ function __wbg_get_imports() {
|
||||
},
|
||||
__wbindgen_cast_0000000000000006: function(arg0, arg1) {
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx: 892, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hc2416b32e405336e);
|
||||
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hd90af689bc3e71bf);
|
||||
return ret;
|
||||
},
|
||||
__wbindgen_cast_0000000000000007: function(arg0, arg1) {
|
||||
@@ -1359,8 +1359,8 @@ function wasm_bindgen__convert__closures_____invoke__h396914cf76a9e7a5(arg0, arg
|
||||
wasm.wasm_bindgen__convert__closures_____invoke__h396914cf76a9e7a5(arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
function wasm_bindgen__convert__closures_____invoke__hdac387fb9e511e9c(arg0, arg1, arg2) {
|
||||
wasm.wasm_bindgen__convert__closures_____invoke__hdac387fb9e511e9c(arg0, arg1, arg2);
|
||||
function wasm_bindgen__convert__closures_____invoke__had771ddc65647798(arg0, arg1, arg2) {
|
||||
wasm.wasm_bindgen__convert__closures_____invoke__had771ddc65647798(arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
function wasm_bindgen__convert__closures_____invoke__h0abd2b2fe4652e2a(arg0, arg1, arg2) {
|
||||
@@ -1371,8 +1371,8 @@ function wasm_bindgen__convert__closures_____invoke__h396914cf76a9e7a5_4(arg0, a
|
||||
wasm.wasm_bindgen__convert__closures_____invoke__h396914cf76a9e7a5_4(arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
function wasm_bindgen__convert__closures_____invoke__hc2416b32e405336e(arg0, arg1, arg2) {
|
||||
wasm.wasm_bindgen__convert__closures_____invoke__hc2416b32e405336e(arg0, arg1, arg2);
|
||||
function wasm_bindgen__convert__closures_____invoke__hd90af689bc3e71bf(arg0, arg1, arg2) {
|
||||
wasm.wasm_bindgen__convert__closures_____invoke__hd90af689bc3e71bf(arg0, arg1, arg2);
|
||||
}
|
||||
|
||||
function wasm_bindgen__convert__closures_____invoke__h3a3182d847094e12(arg0, arg1, arg2) {
|
||||
|
||||
BIN
Binary file not shown.
@@ -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| {
|
||||
|
||||
@@ -22,9 +22,9 @@ use web_sys::{
|
||||
|
||||
use editor_runtime::attachment_upload::dispatch_editor_upload_request;
|
||||
use editor_runtime::block_dnd::{
|
||||
direct_block_from_element, drop_indicator_from_geometry, element_within_handle_shell,
|
||||
event_target_from_point, pointer_in_handle_corridor_geometry, top_level_block_index,
|
||||
HandleCorridorGeometry,
|
||||
direct_block_from_element, direct_block_index_from_element, drop_indicator_from_geometry,
|
||||
element_within_handle_shell, event_target_from_point,
|
||||
pointer_in_handle_corridor_geometry, top_level_block_index, HandleCorridorGeometry,
|
||||
};
|
||||
use editor_runtime::block_menu_overlay;
|
||||
use editor_runtime::block_menu_document::{
|
||||
@@ -4880,13 +4880,7 @@ fn trap_scroll_inside_menu(event: &WheelEvent) {
|
||||
fn hovered_block_from_target(target: web_sys::EventTarget) -> Option<HoveredBlockState> {
|
||||
let root = editor_root_element()?;
|
||||
let element = target_element(target)?;
|
||||
|
||||
if element_within_handle_shell(&element, HANDLE_SHELL_SELECTOR) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let block = direct_block_from_element(element, &root)?;
|
||||
let index = top_level_block_index(&root, &block)?;
|
||||
let index = direct_block_index_from_element(&element, &root, HANDLE_SHELL_SELECTOR)?;
|
||||
block_state_from_index(index)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user