Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions spellcheck_ace.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// You also need to load in typo.js and jquery.js

// You also need to load in nspell.js and jquery.js
const nspell = require('nspell');
// You should configure these classes.
var editor = "editor"; // This should be the id of your editor element.
var lang = "en_US";
var dicPath = "dictionaries/en_US/en_US.dic";
var affPath = "dictionaries/en_US/en_US.aff";
const editor = "editor"; // This should be the id of your editor element.

const dicPath = "dictionaries/en_US/en_US.dic";
const affPath = "dictionaries/en_US/en_US.aff";

// Make red underline for gutter and words.
$("<style type='text/css'>.ace_marker-layer .misspelled { position: absolute; z-index: -2; border-bottom: 1px solid red; margin-bottom: -1px; }</style>").appendTo("head");
Expand All @@ -20,7 +20,7 @@ $.get(dicPath, function(data) {
affData = data;
}).done(function() {
console.log("Dictionary loaded");
dictionary = new Typo(lang, affData, dicData);
dictionary = new nspell(affData, dicData);
});
});

Expand All @@ -32,7 +32,7 @@ function misspelled(line) {
for (word in words) {
var x = words[word] + "";
var checkWord = x.replace(/[^a-zA-Z\-']/g, '');
if (!dictionary.check(checkWord)) {
if (!dictionary.correct(checkWord)) {
bads[bads.length] = [i, i + words[word].length];
}
i += words[word].length + 1;
Expand Down Expand Up @@ -121,10 +121,8 @@ function clear_spellcheck_markers() {
};
}

function suggest_word_for_misspelled(misspelledWord) {
var is_spelled_correctly = dictionary.check(misspelledWord);

function suggest_word_for_misspelled(misspelledWord) {
var array_of_suggestions = dictionary.suggest(misspelledWord);
if (is_spelled_correctly || array_of_suggestions.length === 0) { return false }
if (array_of_suggestions.length === 0) { return false }
return array_of_suggestions
}