How to use the spellchecker.getCorrectionsForMisspelling function in spellchecker

To help you get started, we’ve selected a few spellchecker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Algram / Hypha / app / js / util.js View on Github external
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);
							}
						});
					}
github aluxian / Messenger-for-Desktop / src / scripts / browser / menus / context.js View on Github external
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: () => {
github RocketChat / Rocket.Chat.Electron / src / preload / SpellCheck.js View on Github external
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
github joegesualdo / dictionary-cli / cli.js View on Github external
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;
}
github montanaflynn / Spellcheck-API / server.js View on Github external
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]);
    }
  }
github pacocoursey / Opus / src / renderer / spellcheck.js View on Github external
  getSuggestions: text => spellchecker.getCorrectionsForMisspelling(text),
  isMisspelled: (text) => {
github RocketChat / Rocket.Chat.Electron / src / preload / SpellCheck.js View on Github external
const allCorrections = this.enabledDictionaries.map((dictionary) => {
			checker.setDictionary(dictionary);
			return checker.getCorrectionsForMisspelling(text);
		}).filter((c) => c.length > 0);
github signalapp / Signal-Desktop / js / spell_check.js View on Github external
getSuggestions(text) {
    return spellchecker.getCorrectionsForMisspelling(text);
  },
  add(text) {
github GetPublii / Publii / app / dist / editor-webview-preload.js View on Github external
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();
    }
});