From f466e27884116cf19ab5420fb750abed29991ff3 Mon Sep 17 00:00:00 2001 From: Luke Leppan Date: Wed, 20 Jan 2021 00:41:11 +0200 Subject: [PATCH] Add file count to non-markdown files #5 --- src/main.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 8b5eca0..5bbb555 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,10 @@ -import { MarkdownView, Plugin, TFile, WorkspaceSidedock } from "obsidian"; +import { + MarkdownView, + Plugin, + TFile, + MetadataCache, + getAllTags, +} from "obsidian"; import { BetterWordCountSettingsTab } from "./settings/settings-tab"; import { BetterWordCountSettings } from "./settings/settings"; import { StatusBar } from "./status-bar"; @@ -13,6 +19,8 @@ export default class BetterWordCount extends Plugin { let statusBarEl = this.addStatusBarItem(); this.statusBar = new StatusBar(statusBarEl); + this.updateAltCount(); + this.recentlyTyped = false; this.settings = (await this.loadData()) || new BetterWordCountSettings(); @@ -69,7 +77,7 @@ export default class BetterWordCount extends Plugin { this.recentlyTyped = true; this.updateWordCount(contents); } else { - this.updateWordCount(""); + this.updateAltCount(); } } @@ -83,6 +91,13 @@ export default class BetterWordCount extends Plugin { } } + async updateAltCount() { + // Thanks to Eleanor Konik for the alternate count idea. + const files = this.app.vault.getFiles().length; + + this.statusBar.displayText(`${files} files`); + } + updateWordCount(text: string) { let words: number = 0;