refactor: remove unused block document helpers
This commit is contained in:
@@ -224,3 +224,8 @@ UI / 浏览器可见项必须有真实浏览器截图或结构化 smoke 证据
|
|||||||
- 修改:`rust/spikes/leptos-tiptap-spike/src/editor_runtime/block_menu_document.rs`、`rust/spikes/leptos-tiptap-spike/src/lib.rs`。
|
- 修改:`rust/spikes/leptos-tiptap-spike/src/editor_runtime/block_menu_document.rs`、`rust/spikes/leptos-tiptap-spike/src/lib.rs`。
|
||||||
- 已验证:候选 worktree中 `git diff --check`、`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` 通过;主工作区复跑 `git diff --check`、`cargo fmt --manifest-path rust/Cargo.toml --all --check`、`cargo check --manifest-path rust/spikes/leptos-tiptap-spike/Cargo.toml`、`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` 通过。
|
- 已验证:候选 worktree中 `git diff --check`、`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` 通过;主工作区复跑 `git diff --check`、`cargo fmt --manifest-path rust/Cargo.toml --all --check`、`cargo check --manifest-path rust/spikes/leptos-tiptap-spike/Cargo.toml`、`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` 通过。
|
||||||
- 未完成:`block_menu_document.rs` 中 `duplicate_top_level_block`、`delete_top_level_block`、`reorder_top_level_block` 仍显示无 runtime 调用;是否删除需另起只读审计确认历史测试 / future intent,不在本批扩大。
|
- 未完成:`block_menu_document.rs` 中 `duplicate_top_level_block`、`delete_top_level_block`、`reorder_top_level_block` 仍显示无 runtime 调用;是否删除需另起只读审计确认历史测试 / future intent,不在本批扩大。
|
||||||
|
- 2026-05-25:Batch AA 未派发 Reasonix worker;上一轮刚出现未授权 runner,主控先用 CodeGraph 和 `rg` 核实 `block_menu_document.rs` 中 `duplicate_top_level_block`、`delete_top_level_block`、`reorder_top_level_block` 无 runtime 调用。
|
||||||
|
- Codex 主控完成死链清理:删除上述三组无调用方 JSON helper 和只覆盖该死链的模块内测试;保留真实运行路径 `history_safe_commands::delete_top_level_block_with_history`、`block_menu_legacy_html::{duplicate_top_level_block_html,reorder_top_level_block_html}` 不动。
|
||||||
|
- 修改:`rust/spikes/leptos-tiptap-spike/src/editor_runtime/block_menu_document.rs`。
|
||||||
|
- 已验证:`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:3002 NODE_PATH=/mnt/Data1T/mnote/node_modules node scripts/task479-local-folder-markdown-resource-lifecycle-smoke.js`、`MNOTE_WEB_SMOKE_BASE_URL=http://127.0.0.1:3002 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:3002 NODE_PATH=/mnt/Data1T/mnote/node_modules node scripts/task488-local-attachment-link-delete-undo-smoke.js`。
|
||||||
|
- 验证说明:复用已有 3001 长跑服务时 `task479` 连续两次卡在 missing 标记等待点;改用本批临时启动的干净 3002 服务复跑后通过,判定为长跑服务状态问题,不作为本批回归。
|
||||||
|
|||||||
@@ -2,69 +2,6 @@
|
|||||||
|
|
||||||
use serde_json::{json, Map, Value};
|
use serde_json::{json, Map, Value};
|
||||||
|
|
||||||
use crate::editor_runtime::block_hover_state::DropPlacement;
|
|
||||||
|
|
||||||
fn document_content_mut(document: &mut Value) -> Result<&mut Vec<Value>, String> {
|
|
||||||
document
|
|
||||||
.get_mut("content")
|
|
||||||
.and_then(Value::as_array_mut)
|
|
||||||
.ok_or_else(|| "文档 JSON 缺少顶层 content 数组".to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn duplicate_top_level_block(document: &mut Value, index: usize) -> Result<(), String> {
|
|
||||||
let content = document_content_mut(document)?;
|
|
||||||
let block = content
|
|
||||||
.get(index)
|
|
||||||
.cloned()
|
|
||||||
.ok_or_else(|| format!("找不到第 {index} 个块"))?;
|
|
||||||
content.insert(index + 1, block);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn delete_top_level_block(document: &mut Value, index: usize) -> Result<(), String> {
|
|
||||||
let content = document_content_mut(document)?;
|
|
||||||
if index >= content.len() {
|
|
||||||
return Err(format!("找不到第 {index} 个块"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if content.len() == 1 {
|
|
||||||
content[0] = json!({"type": "paragraph"});
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
content.remove(index);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn reorder_top_level_block(
|
|
||||||
document: &mut Value,
|
|
||||||
source: usize,
|
|
||||||
target: usize,
|
|
||||||
placement: DropPlacement,
|
|
||||||
) -> Result<(), String> {
|
|
||||||
let content = document_content_mut(document)?;
|
|
||||||
if source >= content.len() || target >= content.len() {
|
|
||||||
return Err("拖拽目标超出当前顶层块范围".to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
let block = content.remove(source);
|
|
||||||
let mut insert_at = match placement {
|
|
||||||
DropPlacement::Before => target,
|
|
||||||
DropPlacement::After => target + 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
if source < insert_at {
|
|
||||||
insert_at = insert_at.saturating_sub(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if insert_at > content.len() {
|
|
||||||
insert_at = content.len();
|
|
||||||
}
|
|
||||||
|
|
||||||
content.insert(insert_at, block);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn node_with_attrs(
|
fn node_with_attrs(
|
||||||
type_name: &str,
|
type_name: &str,
|
||||||
attrs: Option<Map<String, Value>>,
|
attrs: Option<Map<String, Value>>,
|
||||||
@@ -115,49 +52,3 @@ pub(crate) fn mindmap_paragraph_node(next_mindmap_id: impl FnOnce() -> String) -
|
|||||||
attrs.insert("projectionVersion".to_string(), json!(1));
|
attrs.insert("projectionVersion".to_string(), json!(1));
|
||||||
node_with_attrs("paragraph", Some(attrs), Vec::new())
|
node_with_attrs("paragraph", Some(attrs), Vec::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use serde_json::json;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn delete_only_top_level_block_keeps_empty_paragraph() {
|
|
||||||
let mut document = json!({
|
|
||||||
"type": "doc",
|
|
||||||
"content": [
|
|
||||||
{"type": "paragraph", "content": [{"type": "text", "text": "A"}]}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
delete_top_level_block(&mut document, 0).expect("delete block");
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
document,
|
|
||||||
json!({"type": "doc", "content": [{"type": "paragraph"}]})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn reorder_top_level_block_adjusts_target_after_source_removal() {
|
|
||||||
let mut document = json!({
|
|
||||||
"type": "doc",
|
|
||||||
"content": [
|
|
||||||
{"type": "paragraph", "attrs": {"id": "a"}},
|
|
||||||
{"type": "paragraph", "attrs": {"id": "b"}},
|
|
||||||
{"type": "paragraph", "attrs": {"id": "c"}}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
reorder_top_level_block(&mut document, 0, 2, DropPlacement::After).expect("reorder block");
|
|
||||||
|
|
||||||
let ids: Vec<_> = document["content"]
|
|
||||||
.as_array()
|
|
||||||
.expect("content")
|
|
||||||
.iter()
|
|
||||||
.map(|node| node["attrs"]["id"].as_str().unwrap_or_default())
|
|
||||||
.collect();
|
|
||||||
assert_eq!(ids, vec!["b", "c", "a"]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user