-
Notifications
You must be signed in to change notification settings - Fork 156
Allow users to add custom words to dictionary #244
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,9 @@ function AbrDocument () { | |
// Start with an empty table of contents | ||
this.toc = []; | ||
|
||
// Custom words | ||
this.words = []; | ||
|
||
// Run this in a background thread | ||
var worker = cp.fork(__dirname + "/toc-worker.js"); | ||
|
||
|
@@ -87,6 +90,18 @@ function AbrDocument () { | |
// Spellchecker init | ||
if (config.spellchecker.active) { | ||
that.setDictionary(config.spellchecker.language, config.spellchecker.src); | ||
|
||
// load custom words | ||
var words = config.spellchecker["custom-words"]; | ||
if (words != null) { | ||
that.words = words; | ||
words.forEach(function (word) { | ||
// just for safety | ||
if (word != "") { | ||
spellchecker.add(word) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
word = word.trim();
if (word) {
spellchecker.add(word);
} (not sure this is useful though) |
||
} | ||
}); | ||
} | ||
} | ||
|
||
// Editor font-size | ||
|
@@ -773,6 +788,15 @@ AbrDocument.prototype = { | |
setDictionary: function (lang, path) { | ||
if (lang) { | ||
spellchecker.setDictionary(lang, path); | ||
|
||
// reload custom words | ||
this.words.forEach(function (word) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same remarks here. |
||
// just for safety | ||
if (word != "") { | ||
spellchecker.add(word) | ||
} | ||
}); | ||
|
||
// Refresh CodeMirror highlight + enable spelling | ||
this.cm.setOption("mode", "abr-spellcheck-on"); | ||
this.setConfig("spellchecker:active", true); | ||
|
@@ -789,6 +813,18 @@ AbrDocument.prototype = { | |
return spellchecker.isMisspelled; | ||
}, | ||
|
||
// Adds the given word to our custom spellcheck-ok words | ||
addSpelledWord: function (word) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid duplicates in config (in case of multiple windows), maybe we can add this here: this.words = this.getConfig("spellchecker:custom-words"); |
||
// add to in-memory spellchecker | ||
spellchecker.add(word); | ||
|
||
// add to config file | ||
if (this.words.indexOf(word) == -1) { | ||
this.words.push(word) | ||
this.setConfig("spellchecker:custom-words", this.words) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing two |
||
} | ||
}, | ||
|
||
// Scale text | ||
setFontSize: function (size) { | ||
var min = 8, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"menu-add-to-dictionary": "Add to Dictionary", | ||
"menu-undo": "Undo", | ||
"menu-redo": "Redo", | ||
"menu-cut": "Cut", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO you can remove this comment.