mirror of
https://github.com/devon22/obsidian-gridexplorer.git
synced 2026-07-22 05:38:16 +00:00
2.9.8
This commit is contained in:
parent
5522f222f4
commit
944096b9e7
10 changed files with 63 additions and 24 deletions
|
|
@ -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",
|
||||
|
|
|
|||
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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": {
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
21
src/main.ts
21
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;
|
||||
|
|
|
|||
|
|
@ -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<TFile> {
|
|||
this.onSubmit = onChoose;
|
||||
}
|
||||
|
||||
// 獲取所有可選的 Markdown 檔案
|
||||
// 獲取所有可選的檔案(僅文件檔)
|
||||
getItems(): TFile[] {
|
||||
return this.app.vault.getMarkdownFiles();
|
||||
return this.app.vault.getFiles().filter((file) => isDocumentFile(file));
|
||||
}
|
||||
|
||||
// 獲取檔案的顯示文本
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
|
|
|
|||
|
|
@ -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': 'Без назви',
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"2.9.7": "1.1.0"
|
||||
"2.9.8": "1.1.0"
|
||||
}
|
||||
Loading…
Reference in a new issue