Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Move learnSpelling and forgetLearnedSpelling to appActions
Browse files Browse the repository at this point in the history
Auditors: @bridiver
  • Loading branch information
darkdh committed Jul 11, 2017
1 parent 309e703 commit f233f7c
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 98 deletions.
83 changes: 0 additions & 83 deletions app/spellCheck.js

This file was deleted.

14 changes: 14 additions & 0 deletions app/spellChecker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const electron = require('electron')
const session = electron.session

module.exports.addWord = (word) => {
session.defaultSession.spellChecker.addWord(word)
}

module.exports.removeWord = (word) => {
session.defaultSession.spellChecker.removeWord(word)
}
14 changes: 14 additions & 0 deletions js/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,20 @@ const appActions = {
actionType: appConstants.APP_SWIPE_RIGHT,
percent
})
},

learnSpelling: function (word) {
dispatch({
actionType: appConstants.APP_LEARN_SPELLING,
word
})
},

forgetLearnedSpelling: function (word) {
dispatch({
actionType: appConstants.APP_FORGET_LEARNED_SPELLING,
word
})
}
}

Expand Down
4 changes: 3 additions & 1 deletion js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ const appConstants = {
APP_ON_CANCEL_BROWSING_DATA: _,
APP_SET_SKIP_SYNC: _,
APP_SWIPE_LEFT: _,
APP_SWIPE_RIGHT: _
APP_SWIPE_RIGHT: _,
APP_LEARN_SPELLING: _,
APP_FORGET_LEARNED_SPELLING: _
}

module.exports = mapValuesByKeys(appConstants)
1 change: 0 additions & 1 deletion js/constants/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ const messages = {
GO_FORWARD: _,
RELOAD: _,
DETACH: _,
IS_MISSPELLED: _, /** @arg {string} word, the word to check */
PASSWORD_DETAILS_UPDATED: _, /** @arg {Object} passwords app state */
PASSWORD_SITE_DETAILS_UPDATED: _, /** @arg {Object} passwords app state */
// Init
Expand Down
23 changes: 10 additions & 13 deletions js/contextMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,19 +543,17 @@ function getMisspelledSuggestions (selection, isMisspelled, suggestions) {
if (isMisspelled) {
template.push({
label: locale.translation('learnSpelling'),
click: (item, focusedWindow) => {
if (focusedWindow) {
focusedWindow.webContents.addWord(selection)
}
click: () => {
appActions.learnSpelling(selection)
webviewActions.replace(selection)
}
}, CommonMenu.separatorMenuItem)
} else {
template.push({
label: locale.translation('forgetLearnedSpelling'),
click: (item, focusedWindow) => {
if (focusedWindow) {
focusedWindow.webContents.removeWord(selection)
}
click: () => {
appActions.forgetLearnedSpelling(selection)
webviewActions.replace(selection)
}
}, CommonMenu.separatorMenuItem)
}
Expand Down Expand Up @@ -955,11 +953,10 @@ function mainTemplateInit (nodeProps, frame, tab) {
if (isInputField) {
let misspelledSuggestions = []
if (nodeProps.misspelledWord) {
if (nodeProps.misspelledWord === 'match-brave-custom-dictionary' && !nodeProps.dictionarySuggestions.length) {
misspelledSuggestions = getMisspelledSuggestions(nodeProps.selectionText, false, nodeProps.dictionarySuggestions)
} else {
misspelledSuggestions = getMisspelledSuggestions(nodeProps.selectionText, true, nodeProps.dictionarySuggestions)
}
misspelledSuggestions = getMisspelledSuggestions(nodeProps.selectionText, true, nodeProps.dictionarySuggestions)
} else if (nodeProps.properties.hasOwnProperty('learnedSpelling') &&
nodeProps.properties['learnedSpelling'] === nodeProps.selectionText) {
misspelledSuggestions = getMisspelledSuggestions(nodeProps.selectionText, false, nodeProps.dictionarySuggestions)
}

const editableItems = getEditableItems(nodeProps.selectionText, nodeProps.editFlags, true)
Expand Down
11 changes: 11 additions & 0 deletions js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const diff = require('immutablediff')
const debounce = require('../lib/debounce')
const path = require('path')
const autofill = require('../../app/autofill')
const spellChecker = require('../../app/spellChecker')
const nativeImage = require('../../app/nativeImage')
const filtering = require('../../app/filtering')
const basicAuth = require('../../app/browser/basicAuth')
Expand Down Expand Up @@ -902,6 +903,16 @@ const handleAppAction = (action) => {
case appConstants.APP_SWIPE_RIGHT:
appState = appState.set('swipeRightPercent', action.percent)
break
case appConstants.APP_LEARN_SPELLING:
if (typeof action.word === 'string') {
spellChecker.addWord(action.word)
}
break
case appConstants.APP_FORGET_LEARNED_SPELLING:
if (typeof action.word === 'string') {
spellChecker.removeWord(action.word)
}
break
default:
}

Expand Down

0 comments on commit f233f7c

Please sign in to comment.