1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/packages/app-desktop/services/spellChecker/SpellCheckerServiceDriverNative.ts

44 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-11-05 18:58:23 +02:00
// Provides spell checking feature via the native Electron built-in spell checker
import SpellCheckerServiceDriverBase from '@joplin/lib/services/spellChecker/SpellCheckerServiceDriverBase';
2020-11-05 18:58:23 +02:00
import bridge from '../bridge';
import Logger from '@joplin/lib/Logger';
const logger = Logger.create('SpellCheckerServiceDriverNative');
2020-11-05 18:58:23 +02:00
export default class SpellCheckerServiceDriverNative extends SpellCheckerServiceDriverBase {
private session(): any {
2020-11-05 18:58:23 +02:00
return bridge().window().webContents.session;
}
public get availableLanguages(): string[] {
2020-11-05 18:58:23 +02:00
return this.session().availableSpellCheckerLanguages;
}
// Language can be set to [] to disable spell-checking
public setLanguages(v: string[]) {
2020-11-05 18:58:23 +02:00
// If we pass an empty array, it disables spell checking
// https://github.com/electron/electron/issues/25228
if (v.length === 0) {
this.session().setSpellCheckerLanguages([]);
return;
}
this.session().setSpellCheckerLanguages(v);
logger.info(`Set effective languages to "${v}"`);
2020-11-05 18:58:23 +02:00
}
public get language(): string {
2020-11-05 18:58:23 +02:00
const languages = this.session().getSpellCheckerLanguages();
return languages.length ? languages[0] : '';
}
public addWordToSpellCheckerDictionary(_language: string, word: string) {
2020-11-05 18:58:23 +02:00
// Actually on Electron all languages share the same dictionary, or
// perhaps it's added to the currently active language.
this.session().addWordToSpellCheckerDictionary(word);
}
}