Skip to content

Commit

Permalink
Added disable/enable methods for hints
Browse files Browse the repository at this point in the history
  • Loading branch information
denisoed committed Feb 21, 2022
1 parent b0cbaa8 commit 282ec71
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cssClasses.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Grammer popup
export const O_POPUP = 'obsidian-orthography-popup';
export const O_POPUP_DISABLED = 'obsidian-orthography-popup--disabled';
export const O_POPUP_CONTROLS = 'obsidian-orthography-popup-controls';
export const O_POPUP_ITEM = 'obsidian-orthography-popup-item';
export const O_POPUP_RESIZED = 'obsidian-orthography-popup--resized';
Expand Down
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export default class OrthographyPlugin extends Plugin {

private async fetchData(text: string): Promise<JSON> {
if (self.aborter) self.aborter.abort();
self.popup.disable();

self.aborter = new AbortController();
const { signal } = self.aborter;
Expand All @@ -182,6 +183,8 @@ export default class OrthographyPlugin extends Plugin {
return await response.json();
} catch (error) {
return error;
} finally {
self.popup.enable();
}
}
}
2 changes: 2 additions & 0 deletions src/orthography/UIElements/UIHints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ const renderHints = (card: IData, index: number): string => {
})
.join('or');
}
// ----------- FOR REMOVE HINTS ----------- //
if (
card.category === 'Formatting' ||
card.category === 'BasicPunct' ||
card.category === 'Wordiness' ||
card.category === 'Conjunctions'
) {
return `
Expand Down
15 changes: 15 additions & 0 deletions src/orthography/orthographyPopup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { App, Events } from 'obsidian';
import { OrthographySettings } from 'src/settings';
import {
O_POPUP,
O_POPUP_DISABLED,
O_POPUP_CONTROLS,
O_POPUP_ITEM,
O_POPUP_RESIZED,
Expand Down Expand Up @@ -71,6 +72,20 @@ export class OrthographyPopup {
this.update(null, false);
}

public disable(): void {
const hints = document.querySelector(`#${O_POPUP}`);
if (hints) {
hints.classList.add(O_POPUP_DISABLED);
}
}

public enable(): void {
const hints = document.querySelector(`#${O_POPUP}`);
if (hints) {
hints.classList.remove(O_POPUP_DISABLED);
}
}

private setListeners() {
const minicards = document.querySelectorAll(`.${O_POPUP_ITEM}`);
minicards.forEach((mc) => mc.addEventListener('click', self.onClickByHint));
Expand Down
5 changes: 5 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
z-index: 15;
}

.obsidian-orthography-popup--disabled {
pointer-events: none;
user-select: none;
}

.obsidian-orthography-popup-item {
width: 100%;
display: flex;
Expand Down

0 comments on commit 282ec71

Please sign in to comment.