fix: 修复本地文件夹垃圾箱恢复聚焦

This commit is contained in:
lix-2026
2026-05-21 14:39:38 +08:00
parent b0fa1e53d8
commit 83ad32dd67
17 changed files with 680 additions and 39 deletions
+34 -5
View File
@@ -60,6 +60,7 @@ pub(crate) struct RootEntryQuery {
workspace_id: Option<String>,
source_kind: Option<String>,
root_uri: Option<String>,
restore_focus_row_id: Option<String>,
}
pub async fn gateway_health(State(state): State<AppState>) -> Response {
@@ -298,8 +299,16 @@ pub async fn root_entry(
);
let sidebar_tree_html =
render_local_sidebar_tree_html(root_uri, selected_active_page_id.as_deref())?;
let file_tree_html =
render_local_file_tree_html(root_uri, selected_active_page_id.as_deref())?;
let restore_focus_row_id = query
.restore_focus_row_id
.as_deref()
.map(str::trim)
.filter(|value| !value.is_empty());
let file_tree_html = render_local_file_tree_html(
root_uri,
selected_active_page_id.as_deref(),
restore_focus_row_id,
)?;
(
workspace_id,
workspace_projection,
@@ -353,7 +362,7 @@ pub async fn root_entry(
let sidebar_tree_html =
render_local_sidebar_tree_html(&root_uri, selected_active_page_id.as_deref())?;
let file_tree_html =
render_local_file_tree_html(&root_uri, selected_active_page_id.as_deref())?;
render_local_file_tree_html(&root_uri, selected_active_page_id.as_deref(), None)?;
(
workspace_id,
workspace_projection,
@@ -567,7 +576,7 @@ pub async fn trash_entry(
let workspace_id =
crate::routes::local_folder_source::local_workspace_id_from_root_uri(root_uri)?;
let sidebar_tree_html = render_local_sidebar_tree_html(root_uri, None).unwrap_or_default();
let file_tree_html = render_local_file_tree_html(root_uri, None).unwrap_or_default();
let file_tree_html = render_local_file_tree_html(root_uri, None, None).unwrap_or_default();
let workspace_projection = build_workspace_shell_projection(
&json!({
"active_workspace_id": workspace_id,
@@ -944,8 +953,15 @@ fn render_local_trash_workbench_html(
let original = escape_html(&entry.original_relative_path);
let trash_path = escape_html(&entry.trash_relative_path);
let kind = escape_html(&entry.resource_kind);
let filetree_row_id = if entry.resource_kind == "markdown"
|| entry.resource_kind == "markdown_bundle"
{
format!("doc:{}", entry.document_id)
} else {
format!("local:asset:{}", entry.original_relative_path)
};
let row = format!(
r#"<article class="mnote-trash-row" data-trash-row="local" data-trash-entry-id="{entry_id}" data-resource-kind="{kind}">
r#"<article class="mnote-trash-row" data-trash-row="local" data-trash-entry-id="{entry_id}" data-resource-kind="{kind}" data-filetree-row-id="{filetree_row_id}">
<div class="mnote-trash-row-main">
<span class="mnote-trash-kind">{kind}</span>
<span class="mnote-trash-title">{original}</span>
@@ -958,6 +974,7 @@ fn render_local_trash_workbench_html(
</article>"#,
entry_id = escape_html(entry_id),
kind = kind,
filetree_row_id = escape_html(&filetree_row_id),
original = original,
trash_path = trash_path,
deleted_at = escape_html(&deleted_at),
@@ -1062,6 +1079,16 @@ fn render_local_trash_workbench_html(
workspaceId: workspaceId,
documentId: entryId
}}).then(function() {{
if (action === 'local-restore') {{
var row = button.closest('[data-trash-row="local"]');
var filetreeRowId = row ? (row.getAttribute('data-filetree-row-id') || '') : '';
if (filetreeRowId && window.localStorage) {{
window.localStorage.setItem('mnote.pendingLocalFolderRestoreFiletreeRowId', filetreeRowId);
}}
if (filetreeRowId) {{
window.name = 'mnote.pendingLocalFolderRestoreFiletreeRowId=' + encodeURIComponent(filetreeRowId);
}}
}}
return refresh();
}}).then(function() {{
setStatus(action === 'local-restore' ? '已恢复项目' : '已彻底删除项目', false);
@@ -2223,6 +2250,8 @@ mod tests {
assert!(html.contains("Deleted"));
assert!(html.contains(r#"data-trash-action="local-restore""#));
assert!(html.contains(r#"data-trash-action="local-purge""#));
assert!(html.contains(r#"data-filetree-row-id="doc:local-md:Deleted~2FDeleted.md""#));
assert!(html.contains("mnote.pendingLocalFolderRestoreFiletreeRowId"));
assert!(html.contains(r#"data-trash-action="local-empty-documents""#));
assert!(html.contains(r#"data-trash-action="local-empty-resources" disabled"#));