This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 973
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9951 from brave/cr-spellchecker
Using Chromium's spellchecker
- Loading branch information
Showing
20 changed files
with
259 additions
and
239 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* 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/. */ | ||
|
||
'use strict' | ||
|
||
const appConstants = require('../../../js/constants/appConstants') | ||
const {makeImmutable} = require('../../common/state/immutableUtil') | ||
const {getWebContents} = require('../webContentsCache') | ||
const spellChecker = require('../../spellChecker') | ||
|
||
const migrate = (state) => { | ||
if (state.get('dictionary')) { | ||
const addedWords = state.getIn(['dictionary', 'addedWords']) | ||
const ignoredWords = state.getIn(['dictionary', 'ignoredWords']) | ||
if (addedWords.size) { | ||
addedWords.forEach((word) => { | ||
spellChecker.addWord(word) | ||
}) | ||
} | ||
if (ignoredWords.size) { | ||
ignoredWords.forEach((word) => { | ||
spellChecker.addWord(word) | ||
}) | ||
} | ||
state = state.delete('dictionary') | ||
} | ||
return state | ||
} | ||
|
||
const spellCheckerReducer = (state, action, immutableAction) => { | ||
action = immutableAction || makeImmutable(action) | ||
switch (action.get('actionType')) { | ||
case appConstants.APP_SET_STATE: | ||
state = migrate(state) | ||
break | ||
case appConstants.APP_SPELLING_SUGGESTED: | ||
if (typeof action.get('suggestion') === 'string') { | ||
const webContents = getWebContents(action.get('tabId')) | ||
if (webContents && !webContents.isDestroyed()) { | ||
webContents.replaceMisspelling(action.get('suggestion')) | ||
} | ||
} | ||
break | ||
case appConstants.APP_LEARN_SPELLING: | ||
if (typeof action.get('word') === 'string') { | ||
spellChecker.addWord(action.get('word')) | ||
const webContents = getWebContents(action.get('tabId')) | ||
if (webContents && !webContents.isDestroyed()) { | ||
webContents.replaceMisspelling(action.get('word')) | ||
} | ||
} | ||
break | ||
case appConstants.APP_FORGET_LEARNED_SPELLING: | ||
if (typeof action.get('word') === 'string') { | ||
spellChecker.removeWord(action.get('word')) | ||
const webContents = getWebContents(action.get('tabId')) | ||
if (webContents && !webContents.isDestroyed()) { | ||
webContents.replace(action.get('word')) | ||
} | ||
} | ||
} | ||
return state | ||
} | ||
|
||
module.exports = spellCheckerReducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.