refactor: extract table selection overlay style

This commit is contained in:
lix-2026
2026-05-25 08:01:27 +08:00
parent 6b39454caf
commit 8b47fed62d
5 changed files with 33 additions and 28 deletions
@@ -272,3 +272,7 @@ UI / 浏览器可见项必须有真实浏览器截图或结构化 smoke 证据
- 修改:`editor_runtime/block_hover_state.rs` 新增 `block_label_for_element(block)``lib.rs` 删除同名实现并通过 import 继续调用。
- 边界:未迁 `block_state_from_index``hovered_block_from_target`、DOM listener 或 block menu signal;本批只外置 Element -> block label 的纯映射。
- 已验证:`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_BIND=127.0.0.1:3013 MNOTE_WEB_PUBLIC_BIND=127.0.0.1:3013 cargo run --manifest-path rust/Cargo.toml -p mnote-web``MNOTE_WEB_SMOKE_BASE_URL=http://127.0.0.1:3013 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:3013 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:3013 NODE_PATH=/mnt/Data1T/mnote/node_modules node scripts/task479-local-folder-markdown-resource-lifecycle-smoke.js`
- 2026-05-25Batch AH 未派发 Reasonix worker;主控本地完成 table selection overlay style 小切片。
- 修改:`editor_runtime/overlays.rs` 新增 `table_selection_overlay_style(anchor, selection)``lib.rs` 删除同名实现并通过 import 继续调用。
- 边界:未迁 table selection signal、row/column click handler、overlay DOM view、`current_table_overlay_anchor` 之外的 table 控件编排或 listener;本批只外置 `TableOverlayAnchor + TableSelectionOverlayState -> CSS style` 的纯样式计算。
- 已验证:`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_BIND=127.0.0.1:3015 MNOTE_WEB_PUBLIC_BIND=127.0.0.1:3015 cargo run --manifest-path rust/Cargo.toml -p mnote-web``MNOTE_WEB_SMOKE_BASE_URL=http://127.0.0.1:3015 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:3015 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:3015 NODE_PATH=/mnt/Data1T/mnote/node_modules node scripts/task479-local-folder-markdown-resource-lifecycle-smoke.js`
@@ -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: 839, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx: 566, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hd90af689bc3e71bf);
return ret;
},
@@ -109,6 +109,32 @@ pub(crate) fn table_col_aux_style(anchor: &TableOverlayAnchor, index: usize) ->
)
}
pub(crate) fn table_selection_overlay_style(
anchor: &TableOverlayAnchor,
selection: &TableSelectionOverlayState,
) -> String {
match selection.kind {
TableSelectionKind::Row => {
let row_height = anchor.height / anchor.rows.max(1) as f64;
format!(
"left:0;top:{:.1}px;width:{:.1}px;height:{:.1}px;",
row_height * selection.index as f64,
anchor.width,
row_height
)
}
TableSelectionKind::Column => {
let col_width = anchor.width / anchor.cols.max(1) as f64;
format!(
"left:{:.1}px;top:0;width:{:.1}px;height:{:.1}px;",
col_width * selection.index as f64,
col_width,
anchor.height
)
}
}
}
pub(crate) fn floating_toolbar_anchor_from_selection() -> Option<FloatingToolbarAnchor> {
let selection = active_editor_text_selection()?;
let range = selection.get_range_at(0).ok()?;
+2 -27
View File
@@ -49,7 +49,8 @@ use editor_runtime::overlays::{
close_editor_floating_overlays_if_escape, open_block_menu_overlay, open_image_toolbar_overlay,
open_slash_menu_overlay, current_table_overlay_anchor, sync_overlays_on_selection_change,
table_col_aux_style, table_overlay_anchor_from_table, table_row_aux_style,
toolbar_overlay_locked, try_sync_editor_overlay_state, FloatingToolbarAnchor,
table_selection_overlay_style, toolbar_overlay_locked, try_sync_editor_overlay_state,
FloatingToolbarAnchor,
ImageToolbarAnchor, TableOverlayAnchor, TableSelectionKind, TableSelectionOverlayState,
};
use editor_runtime::persistence::{
@@ -4885,32 +4886,6 @@ fn block_state_from_index(index: usize) -> Option<HoveredBlockState> {
})
}
fn table_selection_overlay_style(
anchor: &TableOverlayAnchor,
selection: &TableSelectionOverlayState,
) -> String {
match selection.kind {
TableSelectionKind::Row => {
let row_height = anchor.height / anchor.rows.max(1) as f64;
format!(
"left:0;top:{:.1}px;width:{:.1}px;height:{:.1}px;",
row_height * selection.index as f64,
anchor.width,
row_height
)
}
TableSelectionKind::Column => {
let col_width = anchor.width / anchor.cols.max(1) as f64;
format!(
"left:{:.1}px;top:0;width:{:.1}px;height:{:.1}px;",
col_width * selection.index as f64,
col_width,
anchor.height
)
}
}
}
fn prosemirror_node_size(node: &Value) -> Option<u32> {
match node.get("type").and_then(Value::as_str) {
Some("text") => Some(