diff --git a/manifest.json b/manifest.json index 2a34ab3..fe7d563 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "gridexplorer", "name": "GridExplorer", - "version": "3.4.15", + "version": "3.4.16", "minAppVersion": "1.8.7", "description": "Browse and organize note files visually in a flexible grid layout.", "author": "Devon22", diff --git a/package-lock.json b/package-lock.json index 770c40d..99691a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gridexplorer", - "version": "3.4.15", + "version": "3.4.16", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "gridexplorer", - "version": "3.4.15", + "version": "3.4.16", "license": "MIT", "dependencies": { "jszip": "^3.10.1" diff --git a/package.json b/package.json index b364189..ab944fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gridexplorer", - "version": "3.4.15", + "version": "3.4.16", "description": "Browse and organize note files visually in a flexible grid layout.", "main": "main.js", "scripts": { diff --git a/src/GridPreviewManager.ts b/src/GridPreviewManager.ts index 8c82c82..5233d68 100644 --- a/src/GridPreviewManager.ts +++ b/src/GridPreviewManager.ts @@ -320,6 +320,11 @@ export class GridPreviewManager { this.view.noteViewContainer = this.view.containerEl.createDiv('ge-note-view-container'); const noteViewContainer = this.view.noteViewContainer; + // 立即設定狀態,確保在非同步渲染期間也能正常響應關閉或跳轉 + this.view.isShowingNote = true; + this.view.previewedFile = file; + this.view.app.workspace.trigger('ge-preview-file-change', file, this.view); + // 頂部列 (左右區塊) const topBar = noteViewContainer.createDiv('ge-note-top-bar'); const leftBar = topBar.createDiv('ge-note-top-left'); @@ -688,6 +693,7 @@ export class GridPreviewManager { try { // 讀取筆記內容 const content = await this.view.app.vault.read(file); + if (!this.view.isShowingNote || this.view.previewedFile !== file) return; // 使用 Obsidian 的 MarkdownRenderer 渲染內容 await MarkdownRenderer.render( @@ -697,6 +703,7 @@ export class GridPreviewManager { file.path, this.previewComponent! ); + if (!this.view.isShowingNote || this.view.previewedFile !== file) return; // 加上自訂屬性 data-source-path noteContentArea @@ -735,16 +742,10 @@ export class GridPreviewManager { // 渲染反向連結與出站連結區塊 await this.renderLinksSection(file, noteContent); - + if (!this.view.isShowingNote || this.view.previewedFile !== file) return; // 註冊行動裝置滑動手勢 this.registerPreviewTouchEvents(noteViewContainer, scrollContainer, () => this.hideNoteInGrid()); - - // 設定狀態 - this.view.isShowingNote = true; - this.view.previewedFile = file; - // 廣播事件,讓其他 GridView(例如側邊欄的反向連結模式)可以跟著更新 - this.view.app.workspace.trigger('ge-preview-file-change', file, this.view); } // 隱藏筆記顯示 @@ -769,6 +770,10 @@ export class GridPreviewManager { } if (this.view.noteViewContainer) { + // 中斷所有正在下載的圖片,釋放瀏覽器連線池給下一次載入 + this.view.noteViewContainer + .querySelectorAll('img') + .forEach((img) => { img.removeAttribute('src'); }); this.view.noteViewContainer.remove(); this.view.noteViewContainer = null; } diff --git a/src/GridView.ts b/src/GridView.ts index 527fc0c..e0637ad 100644 --- a/src/GridView.ts +++ b/src/GridView.ts @@ -1262,15 +1262,19 @@ export class GridView extends ItemView { // 刪除註解及連結 contentWithoutMediaLinks = contentWithoutMediaLinks .replace(//g, '') - .replace(/!?\[([^\]]*)\]\([^)]+\)|!?\[\[([^\]]+)\]\]/g, (_match: string, p1?: string, p2?: string) => { - const rawLinkText = p1 || p2 || ''; - if (!rawLinkText) return ''; + .replace(/(?:!?\[([^\]]*)\]\(([^)]+)\))|(?:!?\[\[([^\]]+)\]\])/g, (_match: string, p1?: string, p2?: string, p3?: string) => { + if (p3) { + // WikiLink + const wikiLinkParts = p3.split('|'); + const linkTarget = wikiLinkParts[0]; + const linkText = wikiLinkParts.length > 1 ? wikiLinkParts.slice(1).join('|') : p3; + const extension = linkTarget.split('.').pop()?.toLowerCase() || ''; + return (IMAGE_EXTENSIONS.has(extension) || VIDEO_EXTENSIONS.has(extension)) ? '' : linkText; + } - const wikiLinkParts = p2 ? rawLinkText.split('|') : []; - const linkTarget = p2 ? wikiLinkParts[0] : rawLinkText; - const linkText = p2 && wikiLinkParts.length > 1 ? wikiLinkParts.slice(1).join('|') : rawLinkText; - - // 獲取副檔名並檢查是否為圖片或影片 + // Standard Markdown link/image + const linkText = p1 || ''; + const linkTarget = (p2 || '').split('?')[0]; const extension = linkTarget.split('.').pop()?.toLowerCase() || ''; return (IMAGE_EXTENSIONS.has(extension) || VIDEO_EXTENSIONS.has(extension)) ? '' : linkText; });