Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
spellCheck: function (text) {
if (checker.isMisspelled(text)) {
//if this is a misspelling, get suggestions
let options = checker.getCorrectionsForMisspelling(text);
// get the number of suggestions if any
let numSuggestions = options.length ? options.length : 0;
// restrict it to 3 suggestions
let maxItems = numSuggestions > 3 ? 3 : numSuggestions;
let lastSuggestion = null;
// if there are suggestions
if (maxItems > 0) {
for (var i = maxItems - 1; i >= 0; i--) {
let item = options[i];
template.unshift({
label: item,
click: function (menuItem, browserWindow) {
remote.getCurrentWebContents().replaceMisspelling(menuItem.label);
}
// build the new template for the context menu
menu = Menu.buildFromTemplate(template);
//reset the template object
template = [{
label: 'Copy',
role: 'copy',
}, {
label: 'Paste',
role: 'paste',
}, {
label: 'Cut',
role: 'cut',
}];
return !checker.isMisspelled(text);
}
});
isMisspelled: function (text) {
var misspelled = spellchecker.isMisspelled(text);
// The idea is to make this as fast as possible. For the many, many calls which
// don't result in the red squiggly, we minimize the number of checks.
if (!misspelled) {
return false;
}
// Only if we think we've found an error do we check the locale and skip list.
if (appLocale.match(EN_VARIANT) && ENGLISH_SKIP_WORDS.includes(text)) {
return false;
}
return true;
},
getSuggestions: function (text) {
function isMisspelled (word) {
if (contractionMap[word.toLocaleLowerCase()]) {
return false;
}
return nodeSpellcheck.isMisspelled(word);
}
isCorrect(text) {
if (!this.enabledDictionaries.length || this.contractions[text.toLocaleLowerCase()]) {
return true;
}
if (this.multiLanguage) {
for (let i = 0; i < this.enabledDictionaries.length; i++) {
checker.setDictionary(this.enabledDictionaries[i]);
if (!checker.isMisspelled(text)) {
return true;
}
}
} else {
return !checker.isMisspelled(text);
}
return false;
}
return function(next1) {
const noPunc = utils.normalizeWord(word);
if (noPunc && noPunc.length > 0 && options.skipWords.indexOf(noPunc) < 0 && SpellChecker.isMisspelled(noPunc)) {
errors.push({
'line': i,
'index': words.slice(0,j).join(' ').length + 1,
'length': word.length,
'detail': noPunc + ' (Maybe: ' + SpellChecker.getCorrectionsForMisspelling(noPunc) + ')'
});
next1()
} else {
next1();
}
};
}),
const isMisspelled = (word) =>
!appStore.getState().getIn(['dictionary', 'ignoredWords']).includes(word) &&
!appStore.getState().getIn(['dictionary', 'addedWords']).includes(word) &&
spellchecker.isMisspelled(word)
spellCheck: (text) => {
return !SpellChecker.isMisspelled(text);
}
});