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);
}
});
}
function create (params, browserWindow) {
const webContents = browserWindow.webContents;
const menu = new Menu();
if (platform.isDarwin && params.selectionText) {
menu.append(new MenuItem({
label: 'Look Up "' + params.selectionText + '"',
click: () => webContents.send('call-webview-method', 'showDefinitionForSelection')
}));
}
if (params.isEditable && params.misspelledWord) {
const corrections = spellChecker.getCorrectionsForMisspelling(params.misspelledWord);
const items = [];
// add correction suggestions
for (let i = 0; i < corrections.length && i < 5; i++) {
items.push(new MenuItem({
label: 'Correct: ' + corrections[i],
click: () => webContents.send('call-webview-method', 'replaceMisspelling', corrections[i])
}));
}
// Hunspell doesn't remember these, so skip this item
// Otherwise, offer to add the word to the dictionary
if (!platform.isLinux && !params.isWindows7) {
items.push(new MenuItem({
label: 'Add to Dictionary',
click: () => {
getCorrections(text) {
if (!this.multiLanguage) {
return checker.getCorrectionsForMisspelling(text);
}
const allCorrections = this.enabledDictionaries.map((dictionary) => {
checker.setDictionary(dictionary);
return checker.getCorrectionsForMisspelling(text);
}).filter((c) => c.length > 0);
const length = Math.max(...allCorrections.map((a) => a.length));
// Get the best suggestions of each language first
const corrections = [];
for (let i = 0; i < length; i++) {
corrections.push(...allCorrections.map((c) => c[i]).filter((c) => c));
}
// Remove duplicates
console.log(" -s # Show sentences")
console.log(" -f # Show related words")
console.log(" -sd # Show short description")
console.log(" -ld # Show long description")
console.log(" -ld # Show long description")
console.log("Example:\n definition abate -a")
process.exit()
}
if (!args[0]) {
throw new Error("Must provide a word as the first agument")
}
if (SpellChecker.isMisspelled(args[0])) {
var spellingSuggestions = SpellChecker.getCorrectionsForMisspelling(args[0]);
console.log("It looks like the word might be misspelled. Here are some suggestions:")
for(var i = 0; i < spellingSuggestions.length; i++){
console.log(i + 1 + ") " + chalk.underline.blue(spellingSuggestions[i]))
}
return
}
if (argv["s"]) {
showSentences = true;
}
if (argv["f"]) {
showFamily= true;
}
var words = str.split(' ');
var lastChar = getEnding(words[words.length - 1])
var word, noPunctuation, correctSpelling, hasMistakes, hasCorrections;
for (var i = 0; i < words.length; i++) {
word = words[i];
noPunctuation = word.replace(/\W/g, '');
if (getEnding(word)){
word = word.slice(0,-1)
}
if (spc.isMisspelled(word)) {
hasMistakes = true;
correctSpelling = spc.getCorrectionsForMisspelling(word);
if (correctSpelling.length) {
hasCorrections = true;
corrections[word] = correctSpelling;
} else {
corrections[word] = null;
}
}
}
for (correction in corrections) {
if (correction && corrections[correction]) {
var regex = new RegExp(correction, 'g');
str = str.replace(regex, corrections[correction][0]);
}
}
getSuggestions: text => spellchecker.getCorrectionsForMisspelling(text),
isMisspelled: (text) => {
const allCorrections = this.enabledDictionaries.map((dictionary) => {
checker.setDictionary(dictionary);
return checker.getCorrectionsForMisspelling(text);
}).filter((c) => c.length > 0);
getSuggestions(text) {
return spellchecker.getCorrectionsForMisspelling(text);
},
add(text) {
window.addEventListener('contextmenu', () => {
let selectedText = document.getSelection().toString();
let corrections = spellChecker.getCorrectionsForMisspelling(selectedText);
if (corrections.length) {
let contextMenu = new Menu();
for (let i = 0; i < corrections.length; i++) {
contextMenu.append(new MenuItem({
label: corrections[i],
click() {
spellCheckerReplaceSelectedText(corrections[i])
}
}));
}
contextMenu.popup();
}
});