mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #8001 from overleaf/ta-td-refactor-learned-words
Refactor Learned Words Class GitOrigin-RevId: eae6558b5d4eb03b95df511d1cd9ba35b22bb344
This commit is contained in:
parent
3580ec6db3
commit
5a1ff8149d
2 changed files with 37 additions and 9 deletions
|
@ -0,0 +1,31 @@
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
reset() {
|
||||||
|
this.learnedWords = new Set(getMeta('ol-learnedWords'))
|
||||||
|
}
|
||||||
|
|
||||||
|
add(wordText) {
|
||||||
|
this.learnedWords.add(wordText)
|
||||||
|
window.dispatchEvent(
|
||||||
|
new CustomEvent('learnedWords:add', { detail: wordText })
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
has(wordText) {
|
||||||
|
return (
|
||||||
|
this.ignoredMisspellings.has(wordText) || this.learnedWords.has(wordText)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new IgnoredWords()
|
|
@ -1,5 +1,4 @@
|
||||||
import getMeta from '../../../../../utils/meta'
|
import ignoredWords from '../../../../../features/dictionary/ignored-words'
|
||||||
import { IGNORED_MISSPELLINGS } from './IgnoredMisspellings'
|
|
||||||
|
|
||||||
// eslint-disable-next-line prefer-regex-literals
|
// eslint-disable-next-line prefer-regex-literals
|
||||||
const BLACKLISTED_COMMAND_REGEX = new RegExp(
|
const BLACKLISTED_COMMAND_REGEX = new RegExp(
|
||||||
|
@ -62,10 +61,6 @@ class SpellCheckManager {
|
||||||
|
|
||||||
this.selectedHighlightContents = null
|
this.selectedHighlightContents = null
|
||||||
|
|
||||||
this.ignoredMisspellings = new Set(
|
|
||||||
IGNORED_MISSPELLINGS.concat(getMeta('ol-learnedWords'))
|
|
||||||
)
|
|
||||||
|
|
||||||
$(document).on('click', e => {
|
$(document).on('click', e => {
|
||||||
// There is a bug (?) in Safari when ctrl-clicking an element, and the
|
// There is a bug (?) in Safari when ctrl-clicking an element, and the
|
||||||
// the contextmenu event is preventDefault-ed. In this case, the
|
// the contextmenu event is preventDefault-ed. In this case, the
|
||||||
|
@ -198,7 +193,7 @@ class SpellCheckManager {
|
||||||
this.adapter.highlightedWordManager.removeWord(highlight.word)
|
this.adapter.highlightedWordManager.removeWord(highlight.word)
|
||||||
const language = this.$scope.spellCheckLanguage
|
const language = this.$scope.spellCheckLanguage
|
||||||
this.cache.put(`${language}:${highlight.word}`, true)
|
this.cache.put(`${language}:${highlight.word}`, true)
|
||||||
this.ignoredMisspellings.add(highlight.word)
|
ignoredWords.add(highlight.word)
|
||||||
}
|
}
|
||||||
|
|
||||||
markLinesAsUpdated(change) {
|
markLinesAsUpdated(change) {
|
||||||
|
@ -341,7 +336,9 @@ class SpellCheckManager {
|
||||||
apiRequest(endpoint, data, callback) {
|
apiRequest(endpoint, data, callback) {
|
||||||
if (callback == null) {
|
if (callback == null) {
|
||||||
callback = function (error, result) {
|
callback = function (error, result) {
|
||||||
console.error(error)
|
if (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.token = window.user.id
|
data.token = window.user.id
|
||||||
|
@ -384,7 +381,7 @@ class SpellCheckManager {
|
||||||
if (word[word.length - 1] === "'") {
|
if (word[word.length - 1] === "'") {
|
||||||
word = word.slice(0, -1)
|
word = word.slice(0, -1)
|
||||||
}
|
}
|
||||||
if (!this.ignoredMisspellings.has(word)) {
|
if (!ignoredWords.has(word)) {
|
||||||
positions.push({ row: rowIdx, column: result.index })
|
positions.push({ row: rowIdx, column: result.index })
|
||||||
words.push(word)
|
words.push(word)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue