refactor: move body focus detection
This commit is contained in:
@@ -98,7 +98,7 @@ UI / 浏览器可见项必须有真实浏览器截图或结构化 smoke 证据
|
||||
- Codex 已读取 Hindsight recall、`process-handoff.md/json`、`result.json`,并核对 worktree `git status --short` / `git diff --stat` 为空;runner 已产出 completed handoff 但进程未自行退出,主控已终止残留 runner。
|
||||
- 审计结论:当前不宜直接把 `sync_editor_overlay_state` / `try_sync_editor_overlay_state` 迁入 `overlays.rs`,因为它们仍强依赖 `HoveredBlockState`、slash/block menu signals、`active_editor_stage` 和 8/18 overlay signal 的局部关闭策略;`on_selection_change` 仍有一套内联 signal 同步逻辑,直接迁出会造成两套 overlay reconciler。
|
||||
- 下一刀建议:先做类型/边界准备或更窄 helper,而不是迁整个 sync 函数;候选是抽出 block/overlay shared types(例如 `HoveredBlockState` 及相关 anchor 类型)或把 `active_editor_stage` 的 DOM 判断收口到 runtime helper,之后再考虑 `close_editor_floating_overlays` 整簇迁移。
|
||||
- 2026-05-25:Codex 主控完成 editor focus helper 第一刀:新增 `editor_runtime/editor_focus.rs`,迁出 `schedule_editor_focus` 与 `active_editor_stage`;`lib.rs` 仍保留 overlay / block menu signal 编排和调用点。
|
||||
- 2026-05-25:Codex 主控完成 editor focus helper 第一刀:新增 `editor_runtime/editor_focus.rs`,迁出 `schedule_editor_focus`、`body_has_focus` 与 `active_editor_stage`;`lib.rs` 仍保留 overlay / block menu signal 编排和调用点。
|
||||
- 修改:`rust/spikes/leptos-tiptap-spike/src/editor_runtime/editor_focus.rs`、`rust/spikes/leptos-tiptap-spike/src/editor_runtime/mod.rs`、`rust/spikes/leptos-tiptap-spike/src/lib.rs`、generated island wasm/js。
|
||||
- 已验证:`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`、`node scripts/task489-block-menu-delete-undo-smoke.js`、`node scripts/task488-local-attachment-link-delete-undo-smoke.js`。
|
||||
- 未完成:`sync_editor_overlay_state` / `try_sync_editor_overlay_state`、`HoveredBlockState` shared type、block menu signal 仍未拆出。
|
||||
|
||||
+9
-9
@@ -1259,47 +1259,47 @@ function __wbg_get_imports() {
|
||||
}
|
||||
}, arguments); },
|
||||
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 1144, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 1145, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h396914cf76a9e7a5);
|
||||
return ret;
|
||||
},
|
||||
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 1196, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 1197, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
||||
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h3a3182d847094e12);
|
||||
return ret;
|
||||
},
|
||||
__wbindgen_cast_0000000000000003: function(arg0, arg1) {
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 972, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
|
||||
// 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__had771ddc65647798);
|
||||
return ret;
|
||||
},
|
||||
__wbindgen_cast_0000000000000004: function(arg0, arg1) {
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx: 1094, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx: 1095, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h0abd2b2fe4652e2a);
|
||||
return ret;
|
||||
},
|
||||
__wbindgen_cast_0000000000000005: function(arg0, arg1) {
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx: 1144, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx: 1145, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h396914cf76a9e7a5_4);
|
||||
return ret;
|
||||
},
|
||||
__wbindgen_cast_0000000000000006: function(arg0, arg1) {
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx: 724, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx: 527, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hd90af689bc3e71bf);
|
||||
return ret;
|
||||
},
|
||||
__wbindgen_cast_0000000000000007: function(arg0, arg1) {
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1096, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1097, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h794babeffd4f821f);
|
||||
return ret;
|
||||
},
|
||||
__wbindgen_cast_0000000000000008: function(arg0, arg1) {
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1111, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1112, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
|
||||
const ret = makeClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h2b648e7ac8ec1fb5);
|
||||
return ret;
|
||||
},
|
||||
__wbindgen_cast_0000000000000009: function(arg0, arg1) {
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1147, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1148, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h0b7fb40a8610550c);
|
||||
return ret;
|
||||
},
|
||||
|
||||
BIN
Binary file not shown.
@@ -20,6 +20,14 @@ pub(crate) fn schedule_editor_focus(editor: TiptapEditorHandle) {
|
||||
callback.forget();
|
||||
}
|
||||
|
||||
pub(crate) fn body_has_focus() -> bool {
|
||||
window()
|
||||
.and_then(|win| win.document())
|
||||
.and_then(|document| document.active_element())
|
||||
.map(|element| element.tag_name().eq_ignore_ascii_case("body"))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub(crate) fn active_editor_stage() -> bool {
|
||||
let active_element_inside_stage = window()
|
||||
.and_then(|win| win.document())
|
||||
|
||||
@@ -30,7 +30,7 @@ use editor_runtime::command_sync::{
|
||||
use editor_runtime::dom_selection::{
|
||||
has_active_text_selection, selection_summary,
|
||||
};
|
||||
use editor_runtime::editor_focus::{active_editor_stage, schedule_editor_focus};
|
||||
use editor_runtime::editor_focus::{active_editor_stage, body_has_focus, schedule_editor_focus};
|
||||
use editor_runtime::overlays::{
|
||||
floating_toolbar_anchor_from_selection, sync_text_selection_overlay, FloatingToolbarAnchor,
|
||||
};
|
||||
@@ -8284,12 +8284,7 @@ fn App(mount_options: MountOptions) -> impl IntoView {
|
||||
let keydown_handle = window_event_listener(ev::keydown, move |event| {
|
||||
let focused = active_editor_stage();
|
||||
if !focused {
|
||||
let body_has_focus = window()
|
||||
.and_then(|win| win.document())
|
||||
.and_then(|document| document.active_element())
|
||||
.map(|element| element.tag_name().eq_ignore_ascii_case("body"))
|
||||
.unwrap_or(false);
|
||||
if body_has_focus && (event.ctrl_key() || event.meta_key()) && !event.alt_key() {
|
||||
if body_has_focus() && (event.ctrl_key() || event.meta_key()) && !event.alt_key() {
|
||||
let key = event.key();
|
||||
let undo_shortcut = !event.shift_key() && key.eq_ignore_ascii_case("z");
|
||||
let redo_shortcut =
|
||||
|
||||
Reference in New Issue
Block a user