From 6296d6a9e842012528c14fd5d8121015e01b2193 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Wed, 1 Jun 2016 13:04:36 -0400 Subject: [PATCH] Recognize contractions for spell check Fix #2015 Auditors: @aekeus --- CHANGELOG.md | 1 + app/spellCheck.js | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94fabada5a6..873784bcd67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Fixed redownloading files on session restore ([#1219](https://github.com/brave/browser-laptop/issues/1219)) - Fixed pinned tabs sometimes duplicating. ([#1508](https://github.com/brave/browser-laptop/issues/1508)) - Fixed Fullscreen mode showing a black bar up top on OS X. ([#1358](https://github.com/brave/browser-laptop/issues/1358)) +- Fixed contractions showing up as misspelled for spell check. ([#2015](https://github.com/brave/browser-laptop/issues/2015)) - Possibly fixed intermittent problem with copy on OS X. ([#1060](https://github.com/brave/browser-laptop/issues/1060)) - Upgrade to HTTPS Everywhere definitions for 5.1.9. ([#1692](https://github.com/brave/browser-laptop/issues/1692)) - Upgrade to libchromiumcontent 51.0.2704.63. ([#1405](https://github.com/brave/browser-laptop/issues/1405)) diff --git a/app/spellCheck.js b/app/spellCheck.js index 0841cd35005..3f6f9166051 100644 --- a/app/spellCheck.js +++ b/app/spellCheck.js @@ -12,6 +12,8 @@ const ipcMain = electron.ipcMain const app = electron.app const appStore = require('../js/stores/appStore') const appActions = require('../js/actions/appActions') +const contractionSet = new Set() +let dictionaryLocale // Stores a reference to the last added immutable words let lastAddedWords @@ -24,6 +26,10 @@ const isMisspelled = (word) => module.exports.init = () => { ipcMain.on(messages.IS_MISSPELLED, (e, word) => { e.returnValue = isMisspelled(word) + // If the word is misspelled and it's English, then make sure it's nt a contraction. + if (e.returnValue && (!dictionaryLocale || dictionaryLocale.includes('en'))) { + e.returnValue = !contractionSet.has(word) + } }) ipcMain.on(messages.GET_MISSPELLING_INFO, (e, word) => { const misspelled = isMisspelled(word) @@ -44,9 +50,25 @@ module.exports.init = () => { } }) + // Thank you Slack team. + // NB: This is to work around tinyspeck/slack-winssb#267, where contractions + // 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 = app.getLocale().replace('-', '_') - let dictionaryLocale if (availableDictionaries.includes(dict)) { dictionaryLocale = dict } else {