Skip to content

Commit

Permalink
Added handler for close files when open popup
Browse files Browse the repository at this point in the history
  • Loading branch information
denisoed committed Mar 4, 2022
1 parent ecbde66 commit 79df6fa
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/orthography/orthographyToggler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Events } from 'obsidian';
import { Events, Notice } from 'obsidian';
import type { App } from 'obsidian';
import { OrthographySettings } from '../settings';
import { O_RUNNER_ICON, O_RUNNER_ICON_CLEAR } from '../constants';
Expand Down Expand Up @@ -35,14 +35,18 @@ export class OrthographyToggler implements IOrthographyToggler {
}

public toggle(): void {
self.showed = !self.showed;
if (self.showed) {
self.updateButtonText(O_RUNNER_ICON_CLEAR);
self.emitter.trigger('orthography:open');
if (self.getEditor()) {
self.showed = !self.showed;
if (self.showed) {
self.updateButtonText(O_RUNNER_ICON_CLEAR);
self.emitter.trigger('orthography:open');
} else {
self.updateButtonText(O_RUNNER_ICON);
self.removeLoading();
self.emitter.trigger('orthography:close');
}
} else {
self.updateButtonText(O_RUNNER_ICON);
self.removeLoading();
self.emitter.trigger('orthography:close');
new Notice('Please open a file first.');
}
}

Expand Down Expand Up @@ -84,4 +88,9 @@ export class OrthographyToggler implements IOrthographyToggler {
const toggler: HTMLElement = document.querySelector(`.${O_RUNNER}`);
if (toggler) toggler.remove();
}

private getEditor() {
const activeLeaf: any = this.app.workspace.activeLeaf;
return !!activeLeaf.view.sourceMode;
}
}

0 comments on commit 79df6fa

Please sign in to comment.