From e1925c747d2e97033651b387c634c16d286801c9 Mon Sep 17 00:00:00 2001 From: Alexander Juarez Date: Mon, 27 Jun 2016 15:26:05 -0700 Subject: [PATCH] Allow the user to easily add words to the spell check dictionary ops forgot to run coffeelint fixing tests, add back github check hardcode --- lib/spell-check-handler.coffee | 11 ++++++++++- lib/spell-check-task.coffee | 3 ++- lib/spell-check-view.coffee | 3 +++ package.json | 5 +++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/spell-check-handler.coffee b/lib/spell-check-handler.coffee index b44054d1..7a682900 100644 --- a/lib/spell-check-handler.coffee +++ b/lib/spell-check-handler.coffee @@ -1,9 +1,18 @@ SpellChecker = require 'spellchecker' -module.exports = ({id, text}) -> +module.exports = ({id, text, dict}) -> SpellChecker.add("GitHub") SpellChecker.add("github") + dict.filter((word) -> + word + ).forEach (word) -> + word = word.trim() + capitalized = word.charAt(0).toUpperCase() + word.slice(1) + SpellChecker.add(word) + if word isnt capitalized + SpellChecker.add(capitalized) + misspelledCharacterRanges = SpellChecker.checkSpelling(text) row = 0 diff --git a/lib/spell-check-task.coffee b/lib/spell-check-task.coffee index 709c7810..a1ff181d 100644 --- a/lib/spell-check-task.coffee +++ b/lib/spell-check-task.coffee @@ -18,8 +18,9 @@ class SpellCheckTask @constructor.task = null start: (text) -> + dict = atom.config.get('spell-check.dictionary') @constructor.task ?= new Task(require.resolve('./spell-check-handler')) - @constructor.task?.start {@id, text}, @constructor.dispatchMisspellings + @constructor.task?.start {@id, text, dict}, @constructor.dispatchMisspellings onDidSpellCheck: (callback) -> @constructor.callbacksById[@id] = callback diff --git a/lib/spell-check-view.coffee b/lib/spell-check-view.coffee index 966614bf..111b365c 100644 --- a/lib/spell-check-view.coffee +++ b/lib/spell-check-view.coffee @@ -37,6 +37,9 @@ class SpellCheckView @disposables.add atom.config.onDidChange 'spell-check.grammars', => @subscribeToBuffer() + @disposables.add atom.config.onDidChange 'spell-check.dictionary', => + @subscribeToBuffer() + @subscribeToBuffer() @disposables.add @editor.onDidDestroy(@destroy.bind(this)) diff --git a/package.json b/package.json index 974dd63f..552fe62f 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,11 @@ "text.plain.null-grammar" ], "description": "List of scopes for languages which will be checked for misspellings. See [the README](https://github.com/atom/spell-check#spell-check-package-) for more information on finding the correct scope for a specific language." + }, + "dictionary": { + "type": "array", + "default": [], + "description": "list of custom words to accept" } }, "devDependencies": {