mirror of
https://github.com/d7sd6u/obsidian-reveal-folded.git
synced 2026-07-22 05:41:17 +00:00
feat: add auto reveal option
This commit is contained in:
parent
8ffb970a54
commit
30dfc0acaf
8 changed files with 87 additions and 17 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
|
@ -1,3 +1,6 @@
|
|||
[submodule "obsidian-typings"]
|
||||
path = obsidian-typings
|
||||
url = git@github.com:d7sd6u/obsidian-typings.git
|
||||
[submodule "obsidian-reusables"]
|
||||
path = obsidian-reusables
|
||||
url = ssh://git@github.com/d7sd6u/obsidian-reusables.git
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# Reveal Folded
|
||||
|
||||
Reveal the current file in the file explorer while collapsing all other tree items.
|
||||
Reveal the current file in the file explorer while collapsing all other tree items. Has an auto-reveal option for the desktop Obsidian - refocuses active file whenever you move around your vault.
|
||||
|
||||
https://github.com/user-attachments/assets/7169035f-361e-4e6f-91cf-99dbd210a1e9
|
||||
|
||||
|
|
|
|||
1
obsidian-reusables
Submodule
1
obsidian-reusables
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit ead18b5b7d58d16c8083f213915da93ba8ef2873
|
||||
|
|
@ -28,5 +28,7 @@
|
|||
"typescript": "^5.7.3",
|
||||
"typescript-eslint": "^8.24.1"
|
||||
},
|
||||
"dependencies": {}
|
||||
"dependencies": {
|
||||
"monkey-around": "^3.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,11 @@ settings:
|
|||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
dependencies:
|
||||
monkey-around:
|
||||
specifier: ^3.0.0
|
||||
version: 3.0.0
|
||||
|
||||
devDependencies:
|
||||
'@eslint/js':
|
||||
specifier: ^9.20.0
|
||||
|
|
@ -976,6 +981,10 @@ packages:
|
|||
resolution: {integrity: sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==}
|
||||
dev: true
|
||||
|
||||
/monkey-around@3.0.0:
|
||||
resolution: {integrity: sha512-jL6uY2lEAoaHxZep1cNRkCZjoIWY4g5VYCjriEWmcyHU7w8NU1+JH57xE251UVTohK0lCxMjv0ZV4ByDLIXEpw==}
|
||||
dev: false
|
||||
|
||||
/ms@2.1.3:
|
||||
resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
|
||||
dev: true
|
||||
|
|
|
|||
34
src/main.ts
34
src/main.ts
|
|
@ -1,22 +1,33 @@
|
|||
import { Plugin } from "obsidian";
|
||||
import { Platform, TFile } from "obsidian";
|
||||
import PluginWithSettings from "obsidian-reusables/src/PluginWithSettings";
|
||||
import { DEFAULT_SETTINGS, MainPluginSettingsTab } from "./settings";
|
||||
|
||||
export default class RevelFolded extends Plugin {
|
||||
override onload() {
|
||||
export default class RevelFolded extends PluginWithSettings(DEFAULT_SETTINGS) {
|
||||
override async onload() {
|
||||
await this.initSettings(MainPluginSettingsTab);
|
||||
this.addCommand({
|
||||
id: "reveal-active-file-folded",
|
||||
name: "Reveal active file in folded file explorer",
|
||||
icon: "folder-search",
|
||||
checkCallback: (checking) => {
|
||||
const hasActiveFile = !!this.app.workspace.getActiveFile();
|
||||
const activeFile = this.app.workspace.getActiveFile();
|
||||
|
||||
if (!checking && hasActiveFile) this.doCommand();
|
||||
if (!checking && activeFile) this.doCommand(activeFile);
|
||||
|
||||
return hasActiveFile;
|
||||
return !!activeFile;
|
||||
},
|
||||
});
|
||||
|
||||
if (Platform.isDesktop)
|
||||
this.app.workspace.on("file-open", (file) => {
|
||||
const hasActiveFile = this.app.workspace.getActiveFile();
|
||||
|
||||
if (hasActiveFile && file && this.settings.autoReveal)
|
||||
this.doCommand(file);
|
||||
});
|
||||
}
|
||||
|
||||
private doCommand() {
|
||||
private doCommand(file: TFile) {
|
||||
for (const leave of this.app.workspace.getLeavesOfType(
|
||||
"file-explorer",
|
||||
)) {
|
||||
|
|
@ -31,12 +42,13 @@ export default class RevelFolded extends Plugin {
|
|||
leave.view.tree.isAllCollapsed = false;
|
||||
}
|
||||
}, 0);
|
||||
setTimeout(
|
||||
() =>
|
||||
setTimeout(() => {
|
||||
this.app.commands.executeCommandById(
|
||||
"file-explorer:reveal-active-file",
|
||||
),
|
||||
100,
|
||||
);
|
||||
setTimeout(() => {
|
||||
void this.app.workspace.getLeaf().openFile(file);
|
||||
}, 50);
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
43
src/settings.ts
Normal file
43
src/settings.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { App, PluginSettingTab, Setting } from "obsidian";
|
||||
import Main from "./main";
|
||||
import { FolderSuggest } from "../obsidian-reusables/src/FolderSuggest";
|
||||
|
||||
export const DEFAULT_SETTINGS = {
|
||||
autoReveal: false,
|
||||
};
|
||||
export class MainPluginSettingsTab extends PluginSettingTab {
|
||||
constructor(
|
||||
app: App,
|
||||
override plugin: Main,
|
||||
) {
|
||||
super(app, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
suggest?: FolderSuggest;
|
||||
|
||||
display() {
|
||||
const { containerEl } = this;
|
||||
containerEl.empty();
|
||||
const options = Object.fromEntries(
|
||||
this.app.vault.getAllFolders().map((v) => [v.path, v.path]),
|
||||
);
|
||||
options["/"] = "/";
|
||||
|
||||
const setAutoReveal = async (v: boolean) => {
|
||||
this.plugin.settings.autoReveal = v;
|
||||
await this.plugin.saveSettings();
|
||||
};
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Auto reveal")
|
||||
.setDesc(
|
||||
"Automatically reveal your current file (is disabled on mobile)",
|
||||
)
|
||||
.addToggle((toggle) => {
|
||||
toggle
|
||||
.setValue(this.plugin.settings.autoReveal)
|
||||
.onChange(setAutoReveal);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
"target": "ES6",
|
||||
"allowJs": true,
|
||||
"moduleResolution": "node",
|
||||
"importHelpers": true,
|
||||
"importHelpers": false,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"allowImportingTsExtensions": true,
|
||||
|
|
|
|||
Loading…
Reference in a new issue