nsIEditorSpellCheck

Provides spell checking commands for nsIEditor instances.
Inherits from: nsISupports Last changed in Gecko 9.0 (Firefox 9.0 / Thunderbird 9.0 / SeaMonkey 2.6)

Implemented by: @mozilla.org/editor/editorspellchecker;1. To create an instance, use:

var editorSpellCheck = Components.classes["@mozilla.org/editor/editorspellchecker;1"]
                       .createInstance(Components.interfaces.nsIEditorSpellCheck);

Method overview

void AddWordToDictionary(in wstring word);
boolean canSpellCheck();
void checkCurrentDictionary();
boolean CheckCurrentWord(in wstring suggestedWord);
boolean CheckCurrentWordNoSuggest(in wstring suggestedWord);
AString GetCurrentDictionary();
void GetDictionaryList([array, size_is(count)] out wstring dictionaryList, out PRUint32 count);
wstring GetNextMisspelledWord();
void GetPersonalDictionary();
wstring GetPersonalDictionaryWord();
wstring GetSuggestedWord();
void IgnoreWordAllOccurrences(in wstring word);
void InitSpellChecker(in nsIEditor editor, in boolean enableSelectionChecking);
void RemoveWordFromDictionary(in wstring word);
void ReplaceWord(in wstring misspelledWord, in wstring replaceWord, in boolean allOccurrences);
void saveDefaultDictionary(); Obsolete since Gecko 9.0
void SetCurrentDictionary(in AString dictionary);
void setFilter(in nsITextServicesFilter filter);
void UninitSpellChecker();
void UpdateCurrentDictionary();

Methods

AddWordToDictionary()

Adds the specified word to the current personal dictionary.

void AddWordToDictionary(
  in wstring word
);
Parameters
word
The word to add to the current personal dictionary.

Requires Gecko 1.9 (Firefox 3)

canSpellCheck()

Determines whether or not spell checking can be enabled.

boolean canSpellCheck();
Parameters

None.

Return value

Returns true if spell checking can be enabled. If there are no available dictionaries, the return value is false.

Requires Gecko 9.0 (Firefox 9.0 / Thunderbird 9.0 / SeaMonkey 2.6)

checkCurrentDictionary()

Call this after any change in installed dictionaries to ensure that the spell checker is not using a current dictionary which is no longer available. If the current dictionary is no longer available, pick another dictionary.

void checkCurrentDictionary();
Parameters

None.

CheckCurrentWord()

Checks a given word. In spite of the name, this function checks the word you give it, returning true if the word is misspelled. If the word is misspelled, it will compute the suggestions which you can get from GetSuggestedWord().

boolean CheckCurrentWord(
  in wstring suggestedWord
);
Parameters
suggestedWord
Missing Description
Return value

true if the specified word is misspelled; otherwise false.

Requires Gecko 1.8 (Firefox 1.5 / Thunderbird 1.5 / SeaMonkey 1.0)

CheckCurrentWordNoSuggest()

Like CheckCurrentWord(), checks the word you give it, returning true if it is misspelled. This is faster than CheckCurrentWord() because it does not compute any suggestions.

Note: This does not clear any suggestions left over from previous calls to CheckCurrentWord(), so there may be suggestions, but they will be invalid.
boolean CheckCurrentWordNoSuggest(
  in wstring suggestedWord
);
Parameters
suggestedWord
The word to check.
Return value

true if the word is misspelled; otherwise false.

GetCurrentDictionary()

Returns the name of the dictionary currently in use.

AString GetCurrentDictionary();
Parameters

None.

Return value

The name of the dictionary currently in use. Typically, this is an ISO language code, such as "en-US".

GetDictionaryList()

Retrieves a list of the currently available dictionaries. The strings will typically be language IDs, such as "en-US".

void GetDictionaryList(
  [array, size_is(count)] out wstring dictionaryList,
  out PRUint32 count
);
Parameters
dictionaryList
An array into which the list of dictionary name strings are placed.
count
On return, contains the number of entries in the dictionaryList array.

GetNextMisspelledWord()

When interactively spell checking the document, this will return the value of the next word that is misspelled. This also computes the suggestions which you can get by calling GetSuggestedWord().

wstring GetNextMisspelledWord();
Parameters

None.

Return value

The next misspelled word in the document.

GetPersonalDictionary()

Fills an internal list of words added to the personal dictionary. These words can be retrieved using GetPersonalDictionaryWord()

void GetPersonalDictionary();
Parameters

None.

GetPersonalDictionaryWord()

Used after you call GetPersonalDictionary() to iterate through all the words added to the personal dictionary. Returns an empty string when there are no more words.

wstring GetPersonalDictionaryWord();
Parameters

None.

Return value

The next word in the personal dictionary.

GetSuggestedWord()

Used to get suggestions for the last word that was checked and was misspelled. The first call returns the first (best) suggestion. Subsequent calls iterate through all suggestions, allowing you to build a list. When there are no more suggestions, an empty string (not a null pointer) is returned.

wstring GetSuggestedWord();
Parameters

None.

Return value

The next best suggestion for the last word that was checked and was misspelled, or an empty string if there are no remaining suggestions.

IgnoreWordAllOccurrences()

Tells the spell checker to ignore all occurrences of the specified word when spell checking the document.

void IgnoreWordAllOccurrences(
  in wstring word
);
Parameters
word
The word to ignore when spell checking.

InitSpellChecker()

Turns on the spell checker for the given editor.

void InitSpellChecker(
  in nsIEditor editor,
  in boolean enableSelectionChecking
);
Parameters
editor
The nsIEditor on which to enable spell checking.
enableSelectionChecking
If true, the spell checker is initialized only for checking the current selection; otherwise, it's initialized for checking the entire document. This affects the behavior of GetNextMisspelledWord()). For spell checking clients with no modal UI (such as inline spell checkers), this flag is not relevant.

RemoveWordFromDictionary()

Removes a word from the current personal dictionary.

void RemoveWordFromDictionary(
  in wstring word
);
Parameters
word
The word to remove from the current personal dictionary.

ReplaceWord()

Call this function to modally replace one (or all) occurrences of a word with another word.

void ReplaceWord(
  in wstring misspelledWord,
  in wstring replaceWord,
  in boolean allOccurrences
);
Parameters
misspelledWord
The word to replace.
replaceWord
The word with which to replace the misspelledWord.
allOccurrences
If true, all occurrences of misspelledWord are replaced with replaceWord. If false, only the first occurrence is replaced.

Requires Gecko 1.9 (Firefox 3)

saveDefaultDictionary()

Obsolete since Gecko 9.0 (Firefox 9.0 / Thunderbird 9.0 / SeaMonkey 2.6)
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

Saves the currently selected dictionary as the default. The function UninitSpellChecker() will also do this, but that function may not be called in some situations. This function allows the caller to force the default immediately.

Note: This method was removed in Gecko 9.0 (Firefox 9.0 / Thunderbird 9.0 / SeaMonkey 2.6). Since spelling dictionaries can now be selected per-site, this method is no longer needed.
void saveDefaultDictionary();
Parameters

None.

SetCurrentDictionary()

Selects the main dictionary to use.

void SetCurrentDictionary(
  in AString dictionary
);
Parameters
dictionary
The name of the dictionary to use. Typically, this is an ISO language code such as "en-US".

setFilter()

Used to filter the content (for example, to skip blockquotes in email from spell checking). Call this before calling InitSpellChecker(); calling it after initialization will have no effect.

void setFilter(
  in nsITextServicesFilter filter
);
Parameters
filter
An nsITextServicesFilter describing the filter to apply. This filter lets you avoid spell checking specific parts of the document.

UninitSpellChecker()

Call this to release the spell checking object. It will also save the current selected language as the default for future use.

If you have called CanSpellCheck() but not InitSpellChecker(), you can still call this function to clear the cached spell check object, and no preferences are saved.

void UninitSpellChecker();
Parameters

None.

UpdateCurrentDictionary()

Updates the dictionary in use to be sure it corresponds to what the editor needs.

void UpdateCurrentDictionary();
Parameters

None.

Remarks

Prior to Gecko 9.0 (Firefox 9.0 / Thunderbird 9.0 / SeaMonkey 2.6), this method took one parameter, a reference to the nsIEditor for which to update the spell checker. Now that spell checker settings are per-site, this method takes no parameters.

Document Tags and Contributors

 Contributors to this page: Sheppy, amycb, kscarfone
 Last updated by: Sheppy,