mirror of
https://github.com/wenlzhang/obsidian-folder-navigator.git
synced 2026-07-22 05:41:23 +00:00
Add initial version
This commit is contained in:
parent
f398500e4a
commit
5846347772
7 changed files with 5895 additions and 622 deletions
87
README.md
87
README.md
|
|
@ -1,55 +1,48 @@
|
|||
# Plugin Template
|
||||
# Obsidian Folder Navigator
|
||||
|
||||
This is a template for creating plugins for [Obsidian](https://obsidian.md), maintained by [wenlzhang](https://github.com/wenlzhang).
|
||||
A simple plugin for Obsidian that allows you to quickly navigate to folders in your vault using fuzzy search.
|
||||
|
||||
## Getting started
|
||||
## Features
|
||||
|
||||
1. Clone this repository to your local machine
|
||||
2. Update the following files with your plugin information:
|
||||
- `manifest.json`:
|
||||
- `id`: Your plugin ID (in kebab-case)
|
||||
- `name`: Your plugin name
|
||||
- `author`: Your name
|
||||
- `authorUrl`: Your website or GitHub profile URL
|
||||
- `fundingUrl`: Optional funding information
|
||||
- `package.json`:
|
||||
- `name`: Your plugin name (should match manifest.json)
|
||||
- `description`: Your plugin description
|
||||
- `author`: Your name
|
||||
- `keywords`: Relevant keywords for your plugin
|
||||
- Quick folder navigation using fuzzy search
|
||||
- Customizable hotkey (default: Cmd/Ctrl+Shift+O)
|
||||
- Configurable maximum number of search results
|
||||
- Keyboard navigation support
|
||||
- Works with nested folders
|
||||
|
||||
## Usage
|
||||
|
||||
1. Press the hotkey (default: Cmd/Ctrl+Shift+O) to open the folder search modal
|
||||
2. Type to search for folders - the search is fuzzy, so you don't need to type the exact name
|
||||
3. Use arrow keys to navigate through the results
|
||||
4. Press Enter to select a folder and navigate to it in the file explorer
|
||||
|
||||
## Settings
|
||||
|
||||
- **Hotkey**: Customize the keyboard shortcut to open the folder navigator (requires restart)
|
||||
- **Maximum results**: Set the maximum number of folders to show in search results (5-50)
|
||||
|
||||
## Installation
|
||||
|
||||
1. Open Settings in Obsidian
|
||||
2. Navigate to Community Plugins and disable Safe Mode
|
||||
3. Click Browse and search for "Folder Navigator"
|
||||
4. Install the plugin
|
||||
5. Enable the plugin in the Community Plugins tab
|
||||
|
||||
## Manual Installation
|
||||
|
||||
1. Download the latest release
|
||||
2. Extract the files into your vault's `.obsidian/plugins/obsidian-folder-navigator/` directory
|
||||
3. Reload Obsidian
|
||||
4. Enable the plugin in Settings > Community Plugins
|
||||
|
||||
## Development
|
||||
|
||||
1. Install dependencies:
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
1. Clone this repository
|
||||
2. Run `npm i` to install dependencies
|
||||
3. Run `npm run dev` to start compilation in watch mode
|
||||
|
||||
2. Start development server:
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
## License
|
||||
|
||||
3. Build the plugin:
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
## Testing your plugin
|
||||
|
||||
1. Create a test vault in Obsidian
|
||||
2. Create a `.obsidian/plugins` folder in your test vault
|
||||
3. Copy your plugin folder into the plugins folder
|
||||
4. Reload Obsidian to load the plugin (Ctrl/Cmd + R)
|
||||
5. Enable the plugin in Obsidian's settings
|
||||
|
||||
## Publishing your plugin
|
||||
|
||||
1. Update `versions.json` with your plugin's version history
|
||||
2. Test your plugin thoroughly
|
||||
3. Create a GitHub release
|
||||
4. Submit your plugin to the Obsidian Plugin Gallery
|
||||
|
||||
## Support me
|
||||
|
||||
<a href='https://ko-fi.com/C0C66C1TB' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi1.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
|
||||
MIT
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"id": "plugin-template",
|
||||
"name": "Plugin Template",
|
||||
"id": "folder-navigator",
|
||||
"name": "Folder Navigator",
|
||||
"version": "0.0.1",
|
||||
"minAppVersion": "1.0.0",
|
||||
"author": "wenlzhang",
|
||||
|
|
|
|||
6292
package-lock.json
generated
6292
package-lock.json
generated
File diff suppressed because it is too large
Load diff
50
src/folderSuggestModal.ts
Normal file
50
src/folderSuggestModal.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import { App, FuzzySuggestModal, TFolder } from "obsidian";
|
||||
|
||||
export class FolderSuggestModal extends FuzzySuggestModal<TFolder> {
|
||||
folders: TFolder[];
|
||||
|
||||
constructor(app: App) {
|
||||
super(app);
|
||||
this.setPlaceholder("Type folder name...");
|
||||
this.folders = this.getAllFolders();
|
||||
}
|
||||
|
||||
private getAllFolders(): TFolder[] {
|
||||
const folders: TFolder[] = [];
|
||||
const rootFolder = this.app.vault.getRoot();
|
||||
|
||||
const collectFolders = (folder: TFolder) => {
|
||||
folders.push(folder);
|
||||
folder.children.forEach((child) => {
|
||||
if (child instanceof TFolder) {
|
||||
collectFolders(child);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
collectFolders(rootFolder);
|
||||
return folders;
|
||||
}
|
||||
|
||||
getItems(): TFolder[] {
|
||||
return this.folders;
|
||||
}
|
||||
|
||||
getItemText(folder: TFolder): string {
|
||||
return folder.path;
|
||||
}
|
||||
|
||||
onChooseItem(folder: TFolder): void {
|
||||
// Reveal the folder in the navigation
|
||||
const leaf = this.app.workspace.getLeaf();
|
||||
this.app.workspace.revealLeaf(leaf);
|
||||
|
||||
// Focus the folder in the file explorer
|
||||
const fileExplorer =
|
||||
this.app.workspace.getLeavesOfType("file-explorer")[0];
|
||||
if (fileExplorer) {
|
||||
const fileExplorerView = fileExplorer.view as any;
|
||||
fileExplorerView.revealFolder(folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
src/main.ts
33
src/main.ts
|
|
@ -1,8 +1,9 @@
|
|||
import { Plugin } from 'obsidian';
|
||||
import { SettingsTab } from './settingsTab';
|
||||
import { PluginSettings, DEFAULT_SETTINGS } from './settings';
|
||||
import { Plugin } from "obsidian";
|
||||
import { SettingsTab } from "./settingsTab";
|
||||
import { PluginSettings, DEFAULT_SETTINGS } from "./settings";
|
||||
import { FolderSuggestModal } from "./folderSuggestModal";
|
||||
|
||||
export default class MyPlugin extends Plugin {
|
||||
export default class FolderNavigatorPlugin extends Plugin {
|
||||
settings: PluginSettings;
|
||||
|
||||
async onload() {
|
||||
|
|
@ -11,15 +12,15 @@ export default class MyPlugin extends Plugin {
|
|||
// Add settings tab
|
||||
this.addSettingTab(new SettingsTab(this.app, this));
|
||||
|
||||
// Add your plugin's functionality here
|
||||
// For example:
|
||||
// this.addCommand({
|
||||
// id: 'example-command',
|
||||
// name: 'Example Command',
|
||||
// callback: () => {
|
||||
// // Command logic
|
||||
// }
|
||||
// });
|
||||
// Add folder navigation command
|
||||
this.addCommand({
|
||||
id: "open-folder-navigator",
|
||||
name: "Navigate to folder",
|
||||
hotkeys: [{ modifiers: this.settings.hotkey.split("+"), key: "" }],
|
||||
callback: () => {
|
||||
new FolderSuggestModal(this.app).open();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
onunload() {
|
||||
|
|
@ -27,7 +28,11 @@ export default class MyPlugin extends Plugin {
|
|||
}
|
||||
|
||||
async loadSettings() {
|
||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
||||
this.settings = Object.assign(
|
||||
{},
|
||||
DEFAULT_SETTINGS,
|
||||
await this.loadData(),
|
||||
);
|
||||
}
|
||||
|
||||
async saveSettings() {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import { App } from 'obsidian';
|
||||
import { App } from "obsidian";
|
||||
|
||||
export interface PluginSettings {
|
||||
// Add your settings properties here
|
||||
exampleSetting: string;
|
||||
hotkey: string;
|
||||
maxResults: number;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: PluginSettings = {
|
||||
exampleSetting: 'default'
|
||||
hotkey: "Mod+Shift+O",
|
||||
maxResults: 10,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { App, PluginSettingTab, Setting } from 'obsidian';
|
||||
import type MyPlugin from './main';
|
||||
import { App, PluginSettingTab, Setting } from "obsidian";
|
||||
import FolderNavigatorPlugin from "./main";
|
||||
|
||||
export class SettingsTab extends PluginSettingTab {
|
||||
plugin: MyPlugin;
|
||||
plugin: FolderNavigatorPlugin;
|
||||
|
||||
constructor(app: App, plugin: MyPlugin) {
|
||||
constructor(app: App, plugin: FolderNavigatorPlugin) {
|
||||
super(app, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
|
@ -13,17 +13,31 @@ export class SettingsTab extends PluginSettingTab {
|
|||
const { containerEl } = this;
|
||||
containerEl.empty();
|
||||
|
||||
containerEl.createEl('h2', { text: 'Plugin Settings' });
|
||||
new Setting(containerEl)
|
||||
.setName("Hotkey")
|
||||
.setDesc("Hotkey to open folder navigator (requires restart)")
|
||||
.addText((text) =>
|
||||
text
|
||||
.setPlaceholder("Mod+Shift+O")
|
||||
.setValue(this.plugin.settings.hotkey)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.hotkey = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Example Setting')
|
||||
.setDesc('This is an example setting')
|
||||
.addText(text => text
|
||||
.setPlaceholder('Enter your setting')
|
||||
.setValue(this.plugin.settings.exampleSetting)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.exampleSetting = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
.setName("Maximum results")
|
||||
.setDesc("Maximum number of folders to show in search results")
|
||||
.addSlider((slider) =>
|
||||
slider
|
||||
.setLimits(5, 50, 5)
|
||||
.setValue(this.plugin.settings.maxResults)
|
||||
.setDynamicTooltip()
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.maxResults = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue