fix ghost count bug
This commit is contained in:
parent
142923be97
commit
ec914ea36b
1 changed files with 6 additions and 10 deletions
16
src/main.ts
16
src/main.ts
|
@ -4,6 +4,7 @@ import { StatusBar } from "./status-bar";
|
||||||
export default class BetterWordCount extends Plugin {
|
export default class BetterWordCount extends Plugin {
|
||||||
public recentlyTyped: boolean;
|
public recentlyTyped: boolean;
|
||||||
public statusBar: StatusBar;
|
public statusBar: StatusBar;
|
||||||
|
public currentFile: TFile;
|
||||||
|
|
||||||
onload() {
|
onload() {
|
||||||
let statusBarEl = this.addStatusBarItem();
|
let statusBarEl = this.addStatusBarItem();
|
||||||
|
@ -22,14 +23,7 @@ export default class BetterWordCount extends Plugin {
|
||||||
this.registerInterval(
|
this.registerInterval(
|
||||||
window.setInterval(async () => {
|
window.setInterval(async () => {
|
||||||
let activeLeaf = this.app.workspace.activeLeaf;
|
let activeLeaf = this.app.workspace.activeLeaf;
|
||||||
let files: TFile[] = this.app.vault.getMarkdownFiles();
|
|
||||||
let currentFile: TFile;
|
|
||||||
|
|
||||||
files.forEach((file) => {
|
|
||||||
if ((file.basename = activeLeaf.getDisplayText())) {
|
|
||||||
currentFile = file;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!activeLeaf || !(activeLeaf.view instanceof MarkdownView)) {
|
if (!activeLeaf || !(activeLeaf.view instanceof MarkdownView)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -40,11 +34,11 @@ export default class BetterWordCount extends Plugin {
|
||||||
this.updateWordCount(content);
|
this.updateWordCount(content);
|
||||||
this.recentlyTyped = false;
|
this.recentlyTyped = false;
|
||||||
} else if (
|
} else if (
|
||||||
currentFile &&
|
this.currentFile &&
|
||||||
currentFile.extension === "md" &&
|
this.currentFile.extension === "md" &&
|
||||||
!this.recentlyTyped
|
!this.recentlyTyped
|
||||||
) {
|
) {
|
||||||
const contents = await this.app.vault.read(currentFile);
|
const contents = await this.app.vault.read(this.currentFile);
|
||||||
this.updateWordCount(contents);
|
this.updateWordCount(contents);
|
||||||
} else if (!this.recentlyTyped) {
|
} else if (!this.recentlyTyped) {
|
||||||
this.updateWordCount("");
|
this.updateWordCount("");
|
||||||
|
@ -63,6 +57,7 @@ export default class BetterWordCount extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
async onFileOpen(file: TFile) {
|
async onFileOpen(file: TFile) {
|
||||||
|
this.currentFile = file;
|
||||||
if (file && file.extension === "md") {
|
if (file && file.extension === "md") {
|
||||||
const contents = await this.app.vault.cachedRead(file);
|
const contents = await this.app.vault.cachedRead(file);
|
||||||
this.recentlyTyped = true;
|
this.recentlyTyped = true;
|
||||||
|
@ -73,6 +68,7 @@ export default class BetterWordCount extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
onQuickPreview(file: TFile, contents: string) {
|
onQuickPreview(file: TFile, contents: string) {
|
||||||
|
this.currentFile = file;
|
||||||
const leaf = this.app.workspace.activeLeaf;
|
const leaf = this.app.workspace.activeLeaf;
|
||||||
if (leaf && leaf.view.getViewType() === "markdown") {
|
if (leaf && leaf.view.getViewType() === "markdown") {
|
||||||
this.recentlyTyped = true;
|
this.recentlyTyped = true;
|
||||||
|
|
Loading…
Reference in a new issue