overleaf/services/web/frontend/js/features/dictionary/ignored-words.ts
Miguel Serrano 430b7528b2 Merge pull request #8073 from overleaf/ta-td-dictionary
Add UI to Remove Words from Dictionary

GitOrigin-RevId: a28d865e3c968d6fff113237fcf4143b77af046e
2022-05-25 08:09:45 +00:00

40 lines
1 KiB
TypeScript

import getMeta from '../../utils/meta'
import { IGNORED_MISSPELLINGS } from '../../ide/editor/directives/aceEditor/spell-check/IgnoredMisspellings'
export class IgnoredWords {
public learnedWords: Set<string>
private ignoredMisspellings: Set<string>
constructor() {
this.reset()
this.ignoredMisspellings = new Set(IGNORED_MISSPELLINGS)
window.addEventListener('learnedWords:doreset', () => this.reset()) // for tests
}
reset() {
this.learnedWords = new Set(getMeta('ol-learnedWords'))
window.dispatchEvent(new CustomEvent('learnedWords:reset'))
}
add(wordText) {
this.learnedWords.add(wordText)
window.dispatchEvent(
new CustomEvent('learnedWords:add', { detail: wordText })
)
}
remove(wordText) {
this.learnedWords.delete(wordText)
window.dispatchEvent(
new CustomEvent('learnedWords:remove', { detail: wordText })
)
}
has(wordText) {
return (
this.ignoredMisspellings.has(wordText) || this.learnedWords.has(wordText)
)
}
}
export default new IgnoredWords()