Home Reference Source Test Repository
import SpellCheckHandler from 'electron-spellchecker/src/spell-check-handler.js'
public class | source

SpellCheckHandler

SpellCheckHandler is the main class of this library, and handles all of the different pieces of spell checking except for the context menu information.

Instantiate the class, then call {{attachToInput}} to wire it up. The spell checker will attempt to automatically check the language that the user is typing in and switch on-the fly. However, giving it an explicit hint by calling {{switchLanguage}}, or providing it a block of sample text via {{provideHintText}} will result in much better results.

Sample text should be text that is reasonably likely to be in the same language as the user typing - for example, in an Email reply box, the original Email text would be a great sample, or in the case of Slack, the existing channel messages are used as the sample text.

Static Method Summary

Static Public Methods
public static

Override the default logger for this class.

Constructor Summary

Public Constructor
public

constructor(dictionarySync: DictionarySync, localStorage: LocalStorage, scheduler: Scheduler)

Constructs a SpellCheckHandler

Member Summary

Public Members
public
public
public
public
public

disp: *

public
public
public
public
public
public
public
public

Method Summary

Public Methods
public

attachToInput(inputText: Observable<String>): Disposable

Attach to document.body and register ourselves for Electron spell checking.

public

autoUnloadDictionariesOnBlur attempts to save memory by unloading dictionaries when the window loses focus.

public

Disconnect the events that we connected in {{attachToInput}} or other places in the class.

public

getLikelyLocaleForLanguage(language: *): *

Returns the locale for a language code based on the user's machine (i.e. 'en' => 'en-GB')

public

Switch the dictionary language to the language of the sample text provided.

public

Explicitly switch the language to a specific language.

Static Public Methods

public static setLogger(fn: Function) source

Override the default logger for this class. You probably want to use {{setGlobalLogger}} instead

Params:

NameTypeAttributeDescription
fn Function

The function which will operate like console.log

Public Constructors

public constructor(dictionarySync: DictionarySync, localStorage: LocalStorage, scheduler: Scheduler) source

Constructs a SpellCheckHandler

Params:

NameTypeAttributeDescription
dictionarySync DictionarySync

An instance of {{DictionarySync}}, create a custom one if you want to override the dictionary cache location.

localStorage LocalStorage

An implementation of localStorage used for testing.

scheduler Scheduler

The Rx scheduler to use, for testing.

Public Members

public currentSpellchecker: * source

public currentSpellcheckerChanged: * source

public currentSpellcheckerLanguage: * source

public dictionarySync: * source

public disp: * source

public fallbackLocaleTable: * source

public likelyLocaleTable: * source

public localStorage: * source

public scheduler: * source

public shouldAutoCorrect: boolean source

public spellCheckInvoked: * source

public spellingErrorOccurred: * source

public switchToLanguage: * source

Public Methods

public attachToInput(inputText: Observable<String>): Disposable source

Attach to document.body and register ourselves for Electron spell checking. This method will start to watch text entered by the user and automatically switch languages as well as enable Electron spell checking (i.e. the red squigglies).

Params:

NameTypeAttributeDescription
inputText Observable<String>

Simulate the user typing text, for testing.

Return:

Disposable

A Disposable which will unregister all of the things that this method registered.

public autoUnloadDictionariesOnBlur(): Disposable source

autoUnloadDictionariesOnBlur attempts to save memory by unloading dictionaries when the window loses focus.

Return:

Disposable

A {{Disposable}} that will unhook the events listened to by this method.

public dispose() source

Disconnect the events that we connected in {{attachToInput}} or other places in the class.

public getLikelyLocaleForLanguage(language: *): * source

Returns the locale for a language code based on the user's machine (i.e. 'en' => 'en-GB')

Params:

NameTypeAttributeDescription
language *

Return:

*

public provideHintText(inputText: String): Promise source

Switch the dictionary language to the language of the sample text provided. As described in the class documentation, call this method with text most likely in the same language as the user is typing. The locale (i.e. US vs UK vs AU) will be inferred heuristically based on the user's computer.

Params:

NameTypeAttributeDescription
inputText String

A language code (i.e. 'en-US')

Return:

Promise

Completion

public switchLanguage(langCode: String): Promise source

Explicitly switch the language to a specific language. This method will automatically download the dictionary for the specific language and locale and on failure, will attempt to switch to dictionaries that are the same language but a default locale.

Params:

NameTypeAttributeDescription
langCode String

A language code (i.e. 'en-US')

Return:

Promise

Completion