diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8cfec0e..fc5c357 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,7 +15,7 @@ jobs: - name: Install node uses: actions/setup-node@v1 with: - node-version: '10.x' + node-version: '14.x' - name: Install Python uses: actions/setup-python@v2 with: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4a78851..9ced1e4 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,7 +13,7 @@ jobs: - name: Install node uses: actions/setup-node@v1 with: - node-version: '12.x' + node-version: '14.x' registry-url: 'https://registry.npmjs.org' - name: Install Python uses: actions/setup-python@v2 diff --git a/src/index.ts b/src/index.ts index a7b833f..0230b82 100644 --- a/src/index.ts +++ b/src/index.ts @@ -113,13 +113,11 @@ class LanguageManager { * get an array of languages, put "language" in front of the list * the list is alphabetically sorted */ - getChoices(language: IDictionary) { - return [ - language, - ...this.languages - .filter(l => l.id !== language.id) - .sort((a, b) => a.name.localeCompare(b.name)) - ]; + getChoices(language: IDictionary | undefined) { + const options = language + ? [language, ...this.languages.filter(l => l.id !== language.id)] + : this.languages; + return options.sort((a, b) => a.name.localeCompare(b.name)); } /** @@ -168,7 +166,7 @@ class SpellChecker { // Default Options check_spelling = true; - language: IDictionary; + language: IDictionary | undefined; language_manager: LanguageManager; rx_word_char = /[^-[\]{}():/!;&@$£%§<>"*+=?.,~\\^|_`#±\s\t]/; rx_non_word_char = /[-[\]{}():/!;&@$£%§<>"*+=?.,~\\^|_`#±\s\t]/; @@ -495,16 +493,22 @@ class SpellChecker { } load_dictionary() { + const language = this.language; + if (!language) { + return new Promise((accept, reject) => + reject('Cannot load dictionary: no language set') + ); + } this.status_msg = 'Loading dictionary ...'; this.status_widget.update(); return Promise.all([ - fetch(this.language.aff).then(res => res.text()), - fetch(this.language.dic).then(res => res.text()) + fetch(language.aff).then(res => res.text()), + fetch(language.dic).then(res => res.text()) ]).then(values => { - this.dictionary = new Typo(this.language.name, values[0], values[1]); - console.debug('Dictionary Loaded ', this.language.name, this.language.id); + this.dictionary = new Typo(language.name, values[0], values[1]); + console.debug('Dictionary Loaded ', language.name, language.id); - this.status_msg = this.language.name; + this.status_msg = language.name; // update the complete UI this.status_widget.update(); this.refresh_state();