fix(spellcheck): let win < 8 fallback to hunspell

This commit is contained in:
Evan Morikawa 2015-12-11 16:41:41 -05:00
parent 8fe4a7a02f
commit 1d7f9f6cac
2 changed files with 16 additions and 21 deletions

View file

@ -48,9 +48,9 @@ describe "NylasSpellchecker", ->
expect(nodeSpellchecker.setDictionary.calls[0].args[0]).toBe "en_US" expect(nodeSpellchecker.setDictionary.calls[0].args[0]).toBe "en_US"
dict = nodeSpellchecker.setDictionary.calls[0].args[1] dict = nodeSpellchecker.setDictionary.calls[0].args[1]
if process.platform is "darwin" if process.platform is "darwin"
expect(dict.length).toBe 0 expect(dict.length).toBeGreaterThan 0
else if process.platform is "win32" else if process.platform is "win32"
expect(dict.length).toBe 0 expect(dict.length).toBeGreaterThan 0
else if process.platform is "linux" else if process.platform is "linux"
expect(dict.length).toBeGreaterThan 0 expect(dict.length).toBeGreaterThan 0

View file

@ -16,7 +16,7 @@ class NylasSpellchecker
isSpelledCorrectly: (args...) => not @isMisspelled(args...) isSpelledCorrectly: (args...) => not @isMisspelled(args...)
setLanguage: (lang="", dict="") -> setLanguage: (lang="", dict=@_getHunspellDictionary()) ->
@languageAvailable = @isLanguageAvailable(lang) @languageAvailable = @isLanguageAvailable(lang)
if @languageAvailable if @languageAvailable
spellCheck = @isSpelledCorrectly spellCheck = @isSpelledCorrectly
@ -29,24 +29,19 @@ class NylasSpellchecker
@_setWebframeSpellchecker(lang, spellCheck) @_setWebframeSpellchecker(lang, spellCheck)
if process.platform is "linux" # On Mac we defer to NSSpellChecker
dictionaryPath = @_getHunspellDictionary() # On Windows we use the Windows Spell Check API
else #
# On Mac we defer to NSSpellChecker # Both of those automatically provide a set of dictionaries based on
# On Windows we use the Windows Spell Check API # the language string.
# #
# Both of those automatically provide a set of dictionaries based on # On Windows 10 you can see the dictionaries that are available by
# the language string. # looking in: C:\Users\YourName\AppData\Roaming\Microsoft\Spelling
# #
# On Windows 10 you can see the dictionaries that are available by # The `dict` parameter is ignored by node-spellchecker
# looking in: C:\Users\YourName\AppData\Roaming\Microsoft\Spelling #
# # On Linux and old versions of windows we default back to the hunspell
# The `dictionaryPath` parameter is ignored on Mac & Windows by # dictionary
# node-spellchecker
dictionaryPath = ""
if dict.length is 0 then dict = dictionaryPath
spellchecker.setDictionary(lang, dict) spellchecker.setDictionary(lang, dict)
# Separate method for testing # Separate method for testing