Skip to content

Commit

Permalink
Add view-manager.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
HyeonseoNam committed Mar 16, 2023
1 parent cb7599d commit 4093284
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/view-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { App, MarkdownView } from "obsidian";

export class ViewManager {
app: App;

constructor(app: App) {
this.app = app;
}

getSelection(): string | null {
const activeView = this.app.workspace.getActiveViewOfType(MarkdownView);
if (activeView) {
const editor = activeView.editor;
const selectedText = editor.getSelection();
return selectedText;
}
return null;
}

getTitle(): string | null {
const activeView = this.app.workspace.getActiveViewOfType(MarkdownView);
if (activeView) {
return activeView.file.basename;
}
return null;
}

getFrontMatter(): Record<string, unknown> | null {
const activeView = this.app.workspace.getActiveViewOfType(MarkdownView);
if (activeView) {
const file = activeView.file;
const cache = this.app.metadataCache.getFileCache(file);
return cache?.frontmatter || null;
}
return null;
}


}

0 comments on commit 4093284

Please sign in to comment.