refactor: move editor overlay sync helper

This commit is contained in:
lix-2026
2026-05-25 04:53:19 +08:00
parent 74dd955b3d
commit 63d1ea7e47
5 changed files with 62 additions and 52 deletions
@@ -164,3 +164,11 @@ UI / 浏览器可见项必须有真实浏览器截图或结构化 smoke 证据
- 修改:`rust/spikes/leptos-tiptap-spike/src/editor_runtime/overlays.rs``rust/spikes/leptos-tiptap-spike/src/lib.rs`、generated island wasm。
- 已验证:`cargo fmt --manifest-path rust/Cargo.toml --all --check``cargo check --manifest-path rust/spikes/leptos-tiptap-spike/Cargo.toml`、wasm release build、`wasm-bindgen``MNOTE_WEB_SMOKE_BASE_URL=http://127.0.0.1:3001 NODE_PATH=/mnt/Data1T/mnote/node_modules node scripts/task489-block-menu-delete-undo-smoke.js``MNOTE_WEB_SMOKE_BASE_URL=http://127.0.0.1:3001 NODE_PATH=/mnt/Data1T/mnote/node_modules node scripts/task488-local-attachment-link-delete-undo-smoke.js``MNOTE_WEB_SMOKE_BASE_URL=http://127.0.0.1:3001 NODE_PATH=/mnt/Data1T/mnote/node_modules node scripts/task479-local-folder-markdown-resource-lifecycle-smoke.js`
- 未迁:`try_sync_editor_overlay_state``on_selection_change` overlay 同步、`drop_indicator_from_target`、拖拽 listener 和 block reorder 行为。
- 2026-05-25Batch S 只派发 1 个只读 Reasonix worker 审计 `try_sync_editor_overlay_state` 迁出边界,使用独立 worktree `/mnt/Data1T/mnote-worktrees/0525-s-worker-a-5-29-overlay-sync-readonly`run id `reasonix-2026-05-24T20-44-23-926Z-3436b5dd`,并显式使用 `--no-memory-recall`
- Codex 已读取 Hindsight recall、`process-handoff.md/json``result.json``final.md`,并核对 worktree `git status --short` / `git diff --stat` 为空;Reasonix 未修改源码。
- 审计结论经 Codex 复核后采纳:`try_sync_editor_overlay_state` 已无 `lib.rs` 私有依赖,只依赖 `editor_focus::active_editor_stage``floating_toolbar_anchor_from_selection``try_close_block_menu_overlays``FloatingToolbarAnchor``HoveredBlockState`,可机械迁入 `editor_runtime/overlays.rs`
- Codex 主控完成迁移:`try_sync_editor_overlay_state` 迁入 `editor_runtime/overlays.rs``lib.rs` 仅保留 mouseup / keyup listener 调用和仍属于 shell 的 DOM / selection bridge 编排;清理本次迁移产生的孤儿 import。
- 修改:`rust/spikes/leptos-tiptap-spike/src/editor_runtime/overlays.rs``rust/spikes/leptos-tiptap-spike/src/lib.rs`、generated island `js/wasm`
- 已验证:`cargo fmt --manifest-path rust/Cargo.toml --all --check``cargo check --manifest-path rust/spikes/leptos-tiptap-spike/Cargo.toml`、wasm release build、`wasm-bindgen``MNOTE_WEB_SMOKE_BASE_URL=http://127.0.0.1:3001 NODE_PATH=/mnt/Data1T/mnote/node_modules node scripts/task489-block-menu-delete-undo-smoke.js``MNOTE_WEB_SMOKE_BASE_URL=http://127.0.0.1:3001 NODE_PATH=/mnt/Data1T/mnote/node_modules node scripts/task488-local-attachment-link-delete-undo-smoke.js``MNOTE_WEB_SMOKE_BASE_URL=http://127.0.0.1:3001 NODE_PATH=/mnt/Data1T/mnote/node_modules node scripts/task479-local-folder-markdown-resource-lifecycle-smoke.js`
- 环境阻塞:`MNOTE_UI_BASE_URL=http://127.0.0.1:3001 NODE_PATH=/mnt/Data1T/mnote/node_modules node scripts/task158-e30-menu-state-smoke.js` 在创建 cloud 临时文档时返回 `503 convex_unavailable`,当前 3001 服务未配置 Convex mutation;本地文件夹型 editor smoke 已通过。
- 未迁:`on_selection_change` overlay 同步、`drop_indicator_from_target`、拖拽 listener、block reorder 行为和 selection bridge 仍留在 `lib.rs`
@@ -1284,7 +1284,7 @@ function __wbg_get_imports() {
return ret;
},
__wbindgen_cast_0000000000000006: function(arg0, arg1) {
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx: 736, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx: 816, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hd90af689bc3e71bf);
return ret;
},
@@ -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,
+4 -50
View File
@@ -40,11 +40,10 @@ use editor_runtime::dom_selection::{
};
use editor_runtime::editor_focus::{active_editor_stage, body_has_focus, schedule_editor_focus};
use editor_runtime::overlays::{
close_editor_floating_overlays_if_escape, floating_toolbar_anchor_from_selection,
open_block_menu_overlay, open_image_toolbar_overlay, open_slash_menu_overlay,
sync_text_selection_overlay, toolbar_overlay_locked, try_close_block_menu_overlays,
FloatingToolbarAnchor, ImageToolbarAnchor, TableOverlayAnchor, TableSelectionKind,
TableSelectionOverlayState,
close_editor_floating_overlays_if_escape, open_block_menu_overlay, open_image_toolbar_overlay,
open_slash_menu_overlay, sync_text_selection_overlay, toolbar_overlay_locked,
try_sync_editor_overlay_state, FloatingToolbarAnchor, ImageToolbarAnchor, TableOverlayAnchor,
TableSelectionKind, TableSelectionOverlayState,
};
use editor_runtime::persistence::{
load_persisted_document, normalize_identity_value, persist_document_state,
@@ -5647,51 +5646,6 @@ fn replace_top_level_block_kind(
Ok(())
}
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
}
fn apply_html_update(
editor: TiptapEditorHandle,
persisted_identity: &PersistedDocumentIdentity,