diff --git a/manifest.json b/manifest.json index e4fba43..2549eaa 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "gridexplorer", "name": "GridExplorer", - "version": "2.9.7", + "version": "2.9.8", "minAppVersion": "1.1.0", "description": "Browse note files in a grid view.", "author": "Devon22", diff --git a/package-lock.json b/package-lock.json index 979844f..d44b8ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gridexplorer", - "version": "2.9.7", + "version": "2.9.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "gridexplorer", - "version": "2.9.7", + "version": "2.9.8", "license": "MIT", "devDependencies": { "@types/node": "^16.11.6", diff --git a/package.json b/package.json index 42fcc7f..ea30d96 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gridexplorer", - "version": "2.9.7", + "version": "2.9.8", "description": "Browse note files in a grid view.", "main": "main.js", "scripts": { diff --git a/src/GridView.ts b/src/GridView.ts index 18e8208..d3d910d 100644 --- a/src/GridView.ts +++ b/src/GridView.ts @@ -1623,9 +1623,16 @@ export class GridView extends ItemView { let target; if (redirectType === 'file') { - if (redirectPath.startsWith('[[') && redirectPath.endsWith(']]')) { - const noteName = redirectPath.slice(2, -2); - target = this.app.metadataCache.getFirstLinkpathDest(noteName, file.path); + // 支援 ![[...]](嵌入)與 [[file|alias]](別名)格式 + const trimmed = redirectPath.trim(); + const isEmbed = trimmed.startsWith('!'); + const wikilink = isEmbed ? trimmed.substring(1) : trimmed; // 去除前置 '!' + if (wikilink.startsWith('[[') && wikilink.endsWith(']]')) { + let linkInner = wikilink.slice(2, -2).trim(); + // 去除別名部分,例如 "path|alias" -> "path" + const pipeIdx = linkInner.indexOf('|'); + if (pipeIdx !== -1) linkInner = linkInner.substring(0, pipeIdx).trim(); + target = this.app.metadataCache.getFirstLinkpathDest(linkInner, file.path); } else { target = this.app.vault.getAbstractFileByPath(normalizePath(redirectPath)); } diff --git a/src/main.ts b/src/main.ts index 1d01f2e..3c57ae7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -430,22 +430,19 @@ export default class GridExplorerPlugin extends Plugin { } folders.reverse(); // 根 -> 最內層 - // 由於標題麵包屑的最後一段通常是檔名(非資料夾),將其從對映中排除 - const crumbsFolderCount = Math.max(0, crumbs.length - 1); + // 以「去除根目錄('/')」後的資料夾清單,直接用索引對應麵包屑 + const foldersWithoutRoot = folders.filter(f => f.path !== '/'); + const isClickingFileCrumb = (activeFile instanceof TFile) && (clickedIndex === crumbs.length - 1); - // 若點擊最後一段(檔名),目標應為父資料夾(folders 的最後一個) - let targetFolderIndex: number; - if (clickedIndex === crumbs.length - 1) { - targetFolderIndex = Math.max(0, folders.length - 1); + let targetFolder: TFolder | undefined; + if (isClickingFileCrumb) { + // 點到檔名時,導向其父資料夾(foldersWithoutRoot 的最後一個;若不存在則退回根) + targetFolder = foldersWithoutRoot[foldersWithoutRoot.length - 1] ?? folders[0]; } else { - // 其餘情況下,將可見的資料夾麵包屑(通常不含根)對齊到實際資料夾陣列尾端 - const base = Math.max(0, folders.length - crumbsFolderCount); - targetFolderIndex = base + clickedIndex; + // 其他情況,AAA/BBB 與 foldersWithoutRoot[0]/[1] 一一對應 + targetFolder = foldersWithoutRoot[clickedIndex] ?? folders[0]; } - // 邊界保護 - targetFolderIndex = Math.min(Math.max(0, targetFolderIndex), Math.max(0, folders.length - 1)); - const targetFolder = folders[targetFolderIndex]; if (!targetFolder) return; const folderPath = targetFolder.path; diff --git a/src/modal/shortcutSelectionModal.ts b/src/modal/shortcutSelectionModal.ts index 51f59a0..73fdfbe 100644 --- a/src/modal/shortcutSelectionModal.ts +++ b/src/modal/shortcutSelectionModal.ts @@ -1,7 +1,8 @@ import { App, Modal, TFolder, TFile, FuzzySuggestModal } from 'obsidian'; import GridExplorerPlugin from '../main'; -import { t } from '../translations'; import { showSearchInputModal, showUriInputModal, SearchOptions } from './inputModal'; +import { isDocumentFile } from '../fileUtils'; +import { t } from '../translations'; interface ShortcutOption { type: 'mode' | 'folder' | 'file' | 'search' | 'uri'; @@ -214,9 +215,9 @@ class FileSuggestionModal extends FuzzySuggestModal { this.onSubmit = onChoose; } - // 獲取所有可選的 Markdown 檔案 + // 獲取所有可選的檔案(僅文件檔) getItems(): TFile[] { - return this.app.vault.getMarkdownFiles(); + return this.app.vault.getFiles().filter((file) => isDocumentFile(file)); } // 獲取檔案的顯示文本 diff --git a/src/renderHeaderButton.ts b/src/renderHeaderButton.ts index 3ea49a5..7e42a7f 100644 --- a/src/renderHeaderButton.ts +++ b/src/renderHeaderButton.ts @@ -464,6 +464,32 @@ export function renderHeaderButton(gridView: GridView) { } }); }); + // 新增 base + menu.addItem((item) => { + item.setTitle(t('new_base')) + .setIcon('layout-dashboard') + .onClick(async () => { + let newFileName = `${t('untitled')}.base`; + let newFilePath = !gridView.sourcePath || gridView.sourcePath === '/' ? newFileName : `${gridView.sourcePath}/${newFileName}`; + + // 檢查檔案是否已存在,如果存在則遞增編號 + let counter = 1; + while (gridView.app.vault.getAbstractFileByPath(newFilePath)) { + newFileName = `${t('untitled')} ${counter}.base`; + newFilePath = !gridView.sourcePath || gridView.sourcePath === '/' ? newFileName : `${gridView.sourcePath}/${newFileName}`; + counter++; + } + + try { + // 建立新筆記 + const newFile = await gridView.app.vault.create(newFilePath, ''); + // 開啟新筆記 + await gridView.app.workspace.getLeaf().openFile(newFile); + } catch (error) { + console.error('An error occurred while creating a new base:', error); + } + }); + }); // 新增捷徑 menu.addItem((item) => { item.setTitle(t('new_shortcut')) @@ -510,6 +536,7 @@ export function renderHeaderButton(gridView: GridView) { if (gridView.searchQuery) { searchButton.style.display = 'none'; const searchTextContainer = searchButtonContainer.createDiv('ge-search-text-container'); + searchTextContainer.setAttribute('aria-label', gridView.searchQuery); // 創建搜尋文字 const searchText = searchTextContainer.createEl('span', { cls: 'ge-search-text', text: gridView.searchQuery }); diff --git a/src/translations.ts b/src/translations.ts index 303e8c6..de33fa5 100644 --- a/src/translations.ts +++ b/src/translations.ts @@ -40,6 +40,7 @@ export const TRANSLATIONS: Translations = { 'new_note': '新增筆記', 'new_folder': '新增資料夾', 'new_canvas': '新增畫布', + 'new_base': '新增 base', 'new_shortcut': '新增捷徑', 'delete_folder': '刪除資料夾', 'move_folder': '搬移資料夾', @@ -339,6 +340,7 @@ export const TRANSLATIONS: Translations = { 'new_note': 'New note', 'new_folder': 'New folder', 'new_canvas': 'New canvas', + 'new_base': 'New base', 'new_shortcut': 'New shortcut', 'delete_folder': 'Delete Folder', 'move_folder': 'Move Folder', @@ -638,6 +640,7 @@ export const TRANSLATIONS: Translations = { 'new_note': '新建笔记', 'new_folder': '新建文件夹', 'new_canvas': '新建画布', + 'new_base': '新建 base', 'new_shortcut': '新建快捷方式', 'delete_folder': '删除文件夹', 'untitled': '未命名', @@ -935,6 +938,7 @@ export const TRANSLATIONS: Translations = { 'new_note': '新規ノート', 'new_folder': '新規フォルダ', 'new_canvas': '新規キャンバス', + 'new_base': '新規 base', 'new_shortcut': '新規ショートカット', 'delete_folder': '削除フォルダ', 'untitled': '無題', @@ -1233,6 +1237,7 @@ export const TRANSLATIONS: Translations = { 'new_note': 'Новая заметка', 'new_folder': 'Новая папка', 'new_canvas': 'Новый канвас', + 'new_base': 'Новый base', 'new_shortcut': 'Новый ярлык', 'delete_folder': 'Удалить папку', 'untitled': 'Без названия', @@ -1530,6 +1535,7 @@ export const TRANSLATIONS: Translations = { 'new_note': 'Нова нотатка', 'new_folder': 'Нова папка', 'new_canvas': 'Новий канвас', + 'new_base': 'Новий base', 'new_shortcut': 'Новий ярлик', 'delete_folder': 'Видалити папку', 'untitled': 'Без назви', diff --git a/styles.css b/styles.css index fb1db1d..637db53 100644 --- a/styles.css +++ b/styles.css @@ -1063,7 +1063,7 @@ a.ge-current-folder:hover { display: flex; align-items: center; justify-content: flex-start; - max-width: 150px; + max-width: 88px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; @@ -1071,6 +1071,7 @@ a.ge-current-folder:hover { border: 1px solid var(--background-modifier-border); border-radius: 4px; transition: border-color 0.15s ease; + padding: 2px 0; } .ge-search-text-container:hover { diff --git a/versions.json b/versions.json index 7612de5..cbaf610 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,3 @@ { - "2.9.7": "1.1.0" + "2.9.8": "1.1.0" } \ No newline at end of file