refactor: add filetree sidebar snapshot helper

This commit is contained in:
lix-2026
2026-05-25 06:47:54 +08:00
parent 1abc05e4a3
commit cff0c67cf9
4 changed files with 65 additions and 10 deletions
@@ -225,6 +225,20 @@ function replaceSidebarTreeFromDocument(nextDocument, rootId) {
return true;
}
function applyLocalFolderSidebarSnapshot(nextDocument, options) {
options = options || {};
var pageRootId = String(options.pageRootId || 'sidebar-tree-root');
var fileRootId = String(options.fileRootId || 'sidebar-file-tree-root');
var appliedPage = replaceSidebarTreeFromDocument(nextDocument, pageRootId);
var appliedFile = replaceSidebarTreeFromDocument(nextDocument, fileRootId);
var applied = appliedPage || appliedFile;
if (applied && typeof options.onApplied === 'function') options.onApplied({
pageRootApplied: appliedPage,
fileRootApplied: appliedFile
});
return applied;
}
function revealFileTreeRow(row) {
if (!(row instanceof HTMLElement)) return;
var node = row.closest('.tree-node');
@@ -363,6 +377,7 @@ window.__mnoteFileTreeRuntime = {
fileWorkspaceRelativePath: fileWorkspaceRelativePath,
groupRowsByParent: groupRowsByParent,
replaceSidebarTreeFromDocument: replaceSidebarTreeFromDocument,
applyLocalFolderSidebarSnapshot: applyLocalFolderSidebarSnapshot,
fileTreeRowKind: fileTreeRowKind,
fileTreeRowDocumentId: fileTreeRowDocumentId,
fileTreeRowAssetId: fileTreeRowAssetId,