Skip to content

Commit

Permalink
feat!: plugin prioritizes already opened panes
Browse files Browse the repository at this point in the history
close #1
  • Loading branch information
Vinzent03 committed Jun 22, 2021
1 parent 4a533be commit 0541bcb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-typescript": "^6.0.0",
"@types/node": "^14.14.2",
"@types/pdfjs-dist": "^2.1.6",
"obsidian": "https://github.com/obsidianmd/obsidian-api/tarball/master",
"rollup": "^2.32.1",
"tslib": "^2.0.3",
"typescript": "^4.0.3"
},
"dependencies": {
"@popperjs/core": "^2.9.1",
"pdfjs-dist": "^2.5.207"
"@popperjs/core": "^2.9.1"
}
}
}
33 changes: 24 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { App, Plugin, PluginSettingTab, Setting } from 'obsidian';
import { App, MarkdownView, Plugin, PluginSettingTab, Setting, TFile } from 'obsidian';
import { FileSuggest } from './file-suggest';
interface MyPluginSettings {
interface SpecificFilesSettings {
files: string[];
}

const DEFAULT_SETTINGS: MyPluginSettings = {
const DEFAULT_SETTINGS: SpecificFilesSettings = {
files: []
};
export default class MyPlugin extends Plugin {
settings: MyPluginSettings;
export default class SpecificFilesPlugin extends Plugin {
settings: SpecificFilesSettings;
async onload() {
await this.loadSettings();
console.log('loading ' + this.manifest.name);
Expand All @@ -27,20 +27,35 @@ export default class MyPlugin extends Plugin {
async saveSettings() {
await this.saveData(this.settings);
}
setCommands(app: MyPlugin) {
setCommands(app: SpecificFilesPlugin) {
for (const fileName of this.settings.files) {
app.addCommand({
id: fileName,
name: `Open ${fileName.substring(0, fileName.lastIndexOf("."))}`,
callback: () => app.app.workspace.openLinkText(fileName, "")
callback: () => {
let found = false;
this.app.workspace.iterateAllLeaves(leaf => {
const file: TFile = (leaf.view as any).file;
if (file?.path === fileName) {
this.app.workspace.revealLeaf(leaf);
if (leaf.view instanceof MarkdownView) {
leaf.view.editor.focus();
}
found = true;
}
});
if (!found) {
app.app.workspace.openLinkText(fileName, "");
}
}
});
}
}
}

class SettingsTab extends PluginSettingTab {
plugin: MyPlugin;
constructor(app: App, plugin: MyPlugin) {
plugin: SpecificFilesPlugin;
constructor(app: App, plugin: SpecificFilesPlugin) {
super(app, plugin);
this.plugin = plugin;
}
Expand Down

0 comments on commit 0541bcb

Please sign in to comment.