fix local markdown attachment regressions

This commit is contained in:
lix-2026
2026-05-29 11:13:05 +08:00
parent 1109e3c0d8
commit cbe789e034
63 changed files with 3249 additions and 1502 deletions
@@ -1028,20 +1028,35 @@ export const createSidebarFileTreeCommandRuntime = (dependencies = {}) => {
function selectSidebarFileTreeDocument(documentId, options) {
var id = String(documentId || '').trim();
if (!id) return false;
var row = document.querySelector('#sidebar-file-tree-root .tree-row[data-shell-mode="filetree"][data-row-id="' + cssEscape('doc:' + id) + '"]')
var relativePath = options && options.relativePath
? String(options.relativePath || '').trim()
: id.indexOf('local-md:') === 0
? decodeLocalEncodedPath(id.slice('local-md:'.length))
: '';
var targetRowId = options && options.rowId ? String(options.rowId || '').trim() : '';
var row = targetRowId
? document.querySelector('#sidebar-file-tree-root .tree-row[data-shell-mode="filetree"][data-row-id="' + cssEscape(targetRowId) + '"]')
: null;
if (!(row instanceof HTMLElement)) {
row = document.querySelector('#sidebar-file-tree-root .tree-row[data-shell-mode="filetree"][data-row-id="' + cssEscape('doc:' + id) + '"]')
|| document.querySelector('#sidebar-file-tree-root .tree-row[data-shell-mode="filetree"][data-document-id="' + cssEscape(id) + '"]')
|| document.querySelector('#sidebar-file-tree-root .tree-row[data-shell-mode="filetree"][data-doc-id="' + cssEscape(id) + '"]');
}
if (row instanceof HTMLElement && relativePath && fileTreeRowLocalRelativePath(row) !== relativePath) {
row = null;
}
if (row instanceof HTMLElement && row.closest('.tree-children--collapsed') && relativePath && typeof revealFileTreeResource === 'function') {
void revealFileTreeResource({
rootUri: options && options.rootUri,
relativePath: relativePath,
rowId: options && options.rowId,
select: true,
focus: true,
scroll: options ? options.scrollIntoView !== false : true
});
return true;
}
if (!(row instanceof HTMLElement)) {
var relativePath = options && options.relativePath
? String(options.relativePath || '').trim()
: id.indexOf('local-md:') === 0
? decodeLocalEncodedPath(id.slice('local-md:'.length))
: '';
var bundleParentPath = localMarkdownBundleParentPath(relativePath);
var bundleRow = bundleParentPath ? visibleFileTreeRowByRelativePath(bundleParentPath) : null;
if (bundleRow instanceof HTMLElement) {
return activateSidebarFileTreeRow(bundleRow, options);
}
if (relativePath && typeof revealFileTreeResource === 'function') {
void revealFileTreeResource({
rootUri: options && options.rootUri,
@@ -1050,9 +1065,19 @@ export const createSidebarFileTreeCommandRuntime = (dependencies = {}) => {
select: true,
focus: true,
scroll: options ? options.scrollIntoView !== false : true
});
}).then(function(revealed) {
if (revealed) return;
var fallbackParentPath = localMarkdownBundleParentPath(relativePath);
var fallbackBundleRow = fallbackParentPath ? visibleFileTreeRowByRelativePath(fallbackParentPath) : null;
if (fallbackBundleRow instanceof HTMLElement) activateSidebarFileTreeRow(fallbackBundleRow, options);
}).catch(function() {});
return true;
}
var bundleParentPath = localMarkdownBundleParentPath(relativePath);
var bundleRow = bundleParentPath ? visibleFileTreeRowByRelativePath(bundleParentPath) : null;
if (bundleRow instanceof HTMLElement) {
return activateSidebarFileTreeRow(bundleRow, options);
}
return false;
}
return activateSidebarFileTreeRow(row, options);
@@ -1116,25 +1141,33 @@ export const createSidebarFileTreeCommandRuntime = (dependencies = {}) => {
}
document.documentElement.setAttribute('data-mnote-local-folder-restore-focused-row-id', rowId);
document.documentElement.setAttribute('data-mnote-local-folder-restore-focus-status', 'focused');
clearPendingLocalFolderRestoreRowId();
return true;
}
function schedulePendingLocalFolderRestoreFocus() {
function schedulePendingLocalFolderRestoreFocus(options) {
if (!pendingLocalFolderRestoreRowId()) return false;
if (window.__mnotePendingLocalFolderRestoreFocusTimer) return false;
var attempts = 0;
var focused = false;
focused = applyPendingLocalFolderRestoreFocusOnce() || focused;
window.__mnotePendingLocalFolderRestoreFocusTimer = window.setInterval(function() {
attempts += 1;
focused = applyPendingLocalFolderRestoreFocusOnce() || focused;
if (attempts >= 20) {
if (focused) clearPendingLocalFolderRestoreRowId();
else document.documentElement.setAttribute('data-mnote-local-folder-restore-focus-status', 'timeout');
window.clearInterval(window.__mnotePendingLocalFolderRestoreFocusTimer);
window.__mnotePendingLocalFolderRestoreFocusTimer = 0;
}
}, 250);
var reason = options && options.reason ? String(options.reason) : '';
var attempt = Math.max(0, Number(options && options.attempt || 0));
var focused = applyPendingLocalFolderRestoreFocusOnce();
if (focused) return true;
if (attempt >= 4) {
document.documentElement.setAttribute('data-mnote-local-folder-restore-focus-status', 'timeout');
return false;
}
if (window.__mnotePendingLocalFolderRestoreFocusFrame) {
window.cancelAnimationFrame(window.__mnotePendingLocalFolderRestoreFocusFrame);
window.__mnotePendingLocalFolderRestoreFocusFrame = 0;
}
window.__mnotePendingLocalFolderRestoreFocusFrame = window.requestAnimationFrame(function() {
window.__mnotePendingLocalFolderRestoreFocusFrame = 0;
window.setTimeout(function() {
schedulePendingLocalFolderRestoreFocus({
reason: reason || 'retry',
attempt: attempt + 1,
});
}, 60);
});
return focused;
}