How to use spellchecker - 10 common examples

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 brave / browser-laptop / app / spellCheck.js View on Github external
// are incorrectly marked as spelling errors. This lets people get away with
  // incorrectly spelled contracted words, but it's the best we can do for now.
  const contractions = [
    "ain't", "aren't", "can't", "could've", "couldn't", "couldn't've", "didn't", "doesn't", "don't", "hadn't",
    "hadn't've", "hasn't", "haven't", "he'd", "he'd've", "he'll", "he's", "how'd", "how'll", "how's", "I'd",
    "I'd've", "I'll", "I'm", "I've", "isn't", "it'd", "it'd've", "it'll", "it's", "let's", "ma'am", "mightn't",
    "mightn't've", "might've", "mustn't", "must've", "needn't", "not've", "o'clock", "shan't", "she'd", "she'd've",
    "she'll", "she's", "should've", "shouldn't", "shouldn't've", "that'll", "that's", "there'd", "there'd've",
    "there're", "there's", "they'd", "they'd've", "they'll", "they're", "they've", "wasn't", "we'd", "we'd've",
    "we'll", "we're", "we've", "weren't", "what'll", "what're", "what's", "what've", "when's", "where'd",
    "where's", "where've", "who'd", "who'll", "who're", "who's", "who've", "why'll", "why're", "why's", "won't",
    "would've", "wouldn't", "wouldn't've", "y'all", "y'all'd've", "you'd", "you'd've", "you'll", "you're", "you've"
  ]
  contractions.forEach((word) => contractionSet.add(word.replace(/'.*/, '')))

  const availableDictionaries = spellchecker.getAvailableDictionaries()
  let dict = (getSetting(settings.LANGUAGE) || app.getLocale()).replace('-', '_')
  if (availableDictionaries.includes(dict)) {
    dictionaryLocale = dict
    spellchecker.setDictionary(dict)
  } else {
    dict = dict.split('_')[0]
    if (availableDictionaries.includes(dict)) {
      dictionaryLocale = dict
      spellchecker.setDictionary(dict)
    }
  }

  if (dictionaryLocale) {
    appActions.setDictionary(dictionaryLocale)
  }
}
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 Algram / Hypha / app / js / util.js View on Github external
// 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);
		}
	});
github IsmaelMartinez / teams-for-linux / app / browser / rightClickMenuWithSpellcheck.js View on Github external
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) {
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 IsmaelMartinez / teams-for-linux / app / browser / rightClickMenuWithSpellcheck.js View on Github external
function setupLinux(locale) {
	if (process.env.HUNSPELL_DICTIONARIES || locale !== 'en_US') {
		// apt-get install hunspell- can be run for easy access to other dictionaries
		var location = process.env.HUNSPELL_DICTIONARIES || '/usr/share/hunspell';
		spellchecker.setDictionary(locale, location);
	}
}
github RocketChat / Rocket.Chat.Electron / src / preload / SpellCheck.js View on Github external
setEnabled(dictionaries) {
		dictionaries = [].concat(dictionaries);
		let result = false;
		for (let i = 0; i < dictionaries.length; i++) {
			if (this.availableDictionaries.includes(dictionaries[i])) {
				result = true;
				this.enabledDictionaries.push(dictionaries[i]);
				// If using Hunspell or Windows then only allow 1 language for performance reasons
				if (!this.multiLanguage) {
					this.enabledDictionaries = [dictionaries[i]];
					checker.setDictionary(dictionaries[i], this.dictionariesPath);
					return true;
				}
			}
		}
		return result;
	}
github RocketChat / Rocket.Chat.Electron / src / preload / SpellCheck.js View on Github external
loadAvailableDictionaries() {
		this.availableDictionaries = checker.getAvailableDictionaries().sort();
		if (this.availableDictionaries.length === 0) {
			this.multiLanguage = false;
			// Dictionaries path is correct for build
			this.dictionariesPath = path.join(
				app.getAppPath(),
				app.getAppPath().endsWith('app.asar') ? '..' : '.',
				'dictionaries'
			);
			this.getDictionariesFromInstallDirectory();
		} else {
			this.multiLanguage = process.platform !== 'win32';
			this.availableDictionaries = this.availableDictionaries.map((dict) => dict.replace('-', '_'));
		}
	}