Edit view-manager.ts

This commit is contained in:
Hyeonseo Nam 2023-03-17 23:58:07 +09:00
parent 8c59f55dda
commit 45cdadba67

View file

@ -1,4 +1,4 @@
import { App, MarkdownView, Notice, Editor} from "obsidian";
import { App, MarkdownView, Notice, Editor, getAllTags, TagCache} from "obsidian";
export class ViewManager {
app: App;
@ -36,6 +36,19 @@ export class ViewManager {
return null;
}
async getTags(filterRegex?: string): Promise<string[] | null> {
const tagsDict = this.app.metadataCache.getTags();
let tags = Object.keys(tagsDict);
if (!tags || tags.length == 0) return null;
// remove #
tags = tags.map((tag) => tag.replace(/^#/, ''));
// filter
if (filterRegex) {
return tags.filter((tag) => RegExp(filterRegex).test(tag));
}
return tags;
}
async insertAtFrontMatter(key: string, value: string, overwrite = false): Promise<void> {
const activeView = this.app.workspace.getActiveViewOfType(MarkdownView);