refactor: move editor overlay sync helper
This commit is contained in:
@@ -2,7 +2,9 @@ use leptos::prelude::{GetUntracked, ReadSignal, Set, WriteSignal};
|
||||
|
||||
use crate::{
|
||||
editor_runtime::block_hover_state::HoveredBlockState,
|
||||
editor_runtime::dom_selection::active_editor_text_selection, editor_stage_element,
|
||||
editor_runtime::dom_selection::active_editor_text_selection,
|
||||
editor_runtime::editor_focus::active_editor_stage,
|
||||
editor_stage_element,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
@@ -77,6 +79,52 @@ pub(crate) fn sync_text_selection_overlay(
|
||||
has_text_selection
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn try_sync_editor_overlay_state(
|
||||
set_editor_focused: WriteSignal<bool>,
|
||||
set_text_selection_active: WriteSignal<bool>,
|
||||
set_floating_toolbar_anchor: WriteSignal<Option<FloatingToolbarAnchor>>,
|
||||
set_slash_open: WriteSignal<bool>,
|
||||
set_turn_into_open: WriteSignal<bool>,
|
||||
set_hovered_block: WriteSignal<Option<HoveredBlockState>>,
|
||||
set_block_menu_anchor: WriteSignal<Option<HoveredBlockState>>,
|
||||
set_block_menu_open: WriteSignal<bool>,
|
||||
) -> bool {
|
||||
let focused = active_editor_stage();
|
||||
if set_editor_focused.try_set(focused).is_none() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let toolbar_anchor = floating_toolbar_anchor_from_selection();
|
||||
let has_text_selection = toolbar_anchor.is_some();
|
||||
if set_text_selection_active
|
||||
.try_set(has_text_selection)
|
||||
.is_none()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if set_floating_toolbar_anchor
|
||||
.try_set(toolbar_anchor)
|
||||
.is_none()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if focused && has_text_selection {
|
||||
if !try_close_block_menu_overlays(
|
||||
set_slash_open,
|
||||
set_turn_into_open,
|
||||
set_hovered_block,
|
||||
set_block_menu_anchor,
|
||||
set_block_menu_open,
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
pub(crate) fn toolbar_overlay_locked(
|
||||
turn_into_open: bool,
|
||||
color_menu_open: bool,
|
||||
|
||||
Reference in New Issue
Block a user