fix: stabilize block menu undo focus
This commit is contained in:
@@ -36,11 +36,13 @@
|
||||
|
||||
## 根因
|
||||
|
||||
块菜单按钮点击后,删除命令先通过 Tiptap history-safe `delete_range` 路径删除目标块,并在 helper 内调用了一次 `editor.focus()`。但随后 Leptos 继续关闭 block menu / anchor / hovered block 状态,点击目标按钮被卸载,最终浏览器焦点可能落回非 ProseMirror 元素。`Control+Z` 因此没有稳定送到 Tiptap editor,表现为删除成功但撤销不恢复。
|
||||
块菜单按钮点击后,删除命令先通过 Tiptap history-safe `delete_range` 路径删除目标块,history 本身仍可用;浏览器诊断确认删除后点击 editor 再 `Control+Z` 可以恢复 `Beta block`。真正断点是删除菜单关闭期间焦点短暂落到 `BODY`,原 smoke 在焦点恢复前立刻发送 `Control+Z`,快捷键没有稳定送到 Tiptap editor,表现为删除成功但撤销不恢复。
|
||||
|
||||
## 修复
|
||||
|
||||
- 在块菜单删除成功、关闭菜单状态后,再补一次 `editor.focus()`,确保后续键盘撤销进入 ProseMirror。
|
||||
- 删除菜单项 `mousedown` 阶段阻止默认焦点转移,减少按钮卸载后焦点落回 `BODY` 的窗口。
|
||||
- 在块菜单删除成功、关闭菜单状态后,异步补一次 `editor.focus()`,确保正常用户操作后的键盘撤销进入 ProseMirror。
|
||||
- 在 `BODY` 短暂持有焦点时,只兜底转发 `Ctrl/Cmd+Z`、`Ctrl/Cmd+Y`、`Shift+Ctrl/Cmd+Z` 到当前 editor,覆盖 smoke 中删除后立即按撤销的竞态。
|
||||
- 同批拆出 `editor_runtime/block_menu_document.rs`,隔离 legacy 顶层块 JSON helper;当前运行路径仍优先使用 history-safe command,不回退到 HTML 整文替换删除。
|
||||
|
||||
## 验收
|
||||
|
||||
@@ -85,11 +85,12 @@ UI / 浏览器可见项必须有真实浏览器截图或结构化 smoke 证据
|
||||
- 已登记缺陷:`bugs/05-editor-mainline/done/5-39-block-menu-delete-undo-regression-v1.md`。
|
||||
- Worker E(`reasonix-2026-05-24T17-34-41-774Z-85427058`)已在独立 worktree `/mnt/Data1T/mnote-worktrees/0525-b3-block-delete-undo` 派发修复任务,但 runner 仅产出 `prompt.md` / `memory-recall.json` / `reasonix-transcript.jsonl`,无 `final.md`、`result.json`、`process-handoff.md/json`,worktree 无 diff,拒绝采纳。
|
||||
- 当前结论:5-29 仍未完成;下一步应先定位 `delete_top_level_block_with_history`、`sync_persisted_editor_command`、editor focus / undo keydown 之间的真实断点,再修复。
|
||||
- 2026-05-25:Codex 主控修复 `5-39`:块菜单删除成功并关闭菜单状态后追加一次 `editor.focus()`,确保 `Control+Z` 进入 ProseMirror;缺陷文档已移到 `bugs/05-editor-mainline/done/5-39-block-menu-delete-undo-regression-v1.md`。
|
||||
- 2026-05-25:Codex 主控修复 `5-39`:诊断确认 history 未丢,断点是块菜单删除后焦点短暂落到 `BODY`;最终修复为删除菜单项 `mousedown` 阶段阻止默认焦点转移、关闭菜单后异步 `editor.focus()` 兜底,并在 `BODY` 焦点窗口只转发 undo/redo 快捷键到当前 editor;缺陷文档已移到 `bugs/05-editor-mainline/done/5-39-block-menu-delete-undo-regression-v1.md`。
|
||||
- 同批新增 `editor_runtime/block_menu_document.rs`,迁出未走当前运行路径的 legacy 顶层块 JSON helper:`duplicate_top_level_block`、`delete_top_level_block`、`reorder_top_level_block`;`replace_top_level_block_kind` 暂不迁,因仍依赖 slash action、mindmap 和 image placeholder 语义。
|
||||
- 已验证:`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`。
|
||||
- 未覆盖:`cargo test --manifest-path rust/spikes/leptos-tiptap-spike/Cargo.toml block_menu_document -- --test-threads=1` 被既有 `STYLE` 测试编译错误阻断,未进入本次新增 helper 测试。
|
||||
- 2026-05-25:根据用户纠正,后续 B/C/D 等实现 worker 不再只读或在主工作区直接修改;Batch C 统一采用独立 worktree 候选 patch,Codex 读取 Hindsight recall、`process-handoff.md/json`、`result.json`、diff 与验证证据后再选择性合入。
|
||||
- 2026-05-25:Batch C Worker B(`reasonix-2026-05-24T17-41-07-634Z-a39f8963`)在独立 worktree `/mnt/Data1T/mnote-worktrees/0525-c-worker-b-block-delete-undo` 未产出 `final.md`、`result.json` 或 `process-handoff.md/json`,worktree diff 为空,拒绝采纳;Codex 随后在同一 worktree 独立定位根因、产出候选 patch、通过 smoke 后移植到主工作区。
|
||||
- 2026-05-25:Reasonix 只读审计 `sync_editor_overlay_state` / `try_sync_editor_overlay_state` 下一刀,使用独立 worktree `/mnt/Data1T/mnote-worktrees/0525-d-5-29-overlay-readonly`,run id `reasonix-2026-05-24T17-53-20-962Z-d3077308`。
|
||||
- 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。
|
||||
|
||||
+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: 1138, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 1144, 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: 1190, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
||||
// 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`.
|
||||
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: 966, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 972, 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: 1088, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx: 1094, 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: 1138, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx: 1144, 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: 713, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx: 882, 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: 1090, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1096, 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: 1105, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1111, 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: 1141, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
||||
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 1147, 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.
@@ -3655,6 +3655,20 @@ fn schedule_scroll_mnote_block_anchor_from_hash_retry(remaining: u8) {
|
||||
callback.forget();
|
||||
}
|
||||
|
||||
fn schedule_editor_focus(editor: TiptapEditorHandle) {
|
||||
let Some(win) = window() else {
|
||||
return;
|
||||
};
|
||||
let callback = Closure::<dyn FnMut()>::new(move || {
|
||||
let _ = editor.focus();
|
||||
});
|
||||
let _ = win.set_timeout_with_callback_and_timeout_and_arguments_0(
|
||||
callback.as_ref().unchecked_ref(),
|
||||
0,
|
||||
);
|
||||
callback.forget();
|
||||
}
|
||||
|
||||
fn current_viewport_scroll() -> Option<(f64, f64)> {
|
||||
let win = window()?;
|
||||
let x = win.scroll_x().ok()?;
|
||||
@@ -8313,6 +8327,28 @@ 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() {
|
||||
let key = event.key();
|
||||
let undo_shortcut = !event.shift_key() && key.eq_ignore_ascii_case("z");
|
||||
let redo_shortcut =
|
||||
key.eq_ignore_ascii_case("y")
|
||||
|| (event.shift_key() && key.eq_ignore_ascii_case("z"));
|
||||
if undo_shortcut || redo_shortcut {
|
||||
event.prevent_default();
|
||||
if redo_shortcut {
|
||||
let _ = editor.redo();
|
||||
} else {
|
||||
let _ = editor.undo();
|
||||
}
|
||||
schedule_editor_focus(editor);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -10092,6 +10128,10 @@ fn App(mount_options: MountOptions) -> impl IntoView {
|
||||
<button
|
||||
class="block-drag-menu-item"
|
||||
data-testid="block-drag-menu-item-delete"
|
||||
on:mousedown=move |event: MouseEvent| {
|
||||
event.prevent_default();
|
||||
event.stop_propagation();
|
||||
}
|
||||
on:click=move |event: MouseEvent| {
|
||||
event.stop_propagation();
|
||||
match editor_runtime::history_safe_commands::delete_top_level_block_with_history(&editor, block_index) {
|
||||
@@ -10110,7 +10150,7 @@ fn App(mount_options: MountOptions) -> impl IntoView {
|
||||
set_block_menu_open.set(false);
|
||||
set_block_menu_anchor.set(None);
|
||||
set_hovered_block.set(None);
|
||||
let _ = editor.focus();
|
||||
schedule_editor_focus(editor);
|
||||
}
|
||||
Err(err) => set_command_feedback.set(err),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user