Skip to content

Commit 96a2935

Browse files
authored
Merge pull request #1463 from Hirobreak/spellchecker
spellchecker alternative
2 parents 10a3b3d + d3de34c commit 96a2935

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

electron_app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
"rimraf": "^2.6.3",
175175
"rmdir-recursive": "^0.0.1",
176176
"sequelize": "^5.21.2",
177+
"spellchecker": "^3.7.0",
177178
"sqlite3": "^4.1.0",
178179
"umzug": "^2.2.0",
179180
"unused-filename": "^2.1.0",

electron_app/src/windows/composer.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { EVENTS, callEvent } = require('./events');
77
const fileUtils = require('../utils/FileUtils');
88
const { API_TRACKING_EVENT } = require('../utils/const');
99
const { filterInvalidEmailAddresses } = require('./../utils/EmailUtils');
10+
const spellChecker = require('spellchecker');
1011

1112
const lang = require('./../lang');
1213
const { windowTitle } = lang.strings.windows.composer;
@@ -87,7 +88,28 @@ const createComposerWindow = () => {
8788
window,
8889
showSaveImageAs: false,
8990
showInspectElement: false,
90-
showCopyImageAddress: false
91+
showCopyImageAddress: false,
92+
prepend: (defaultActions, browserWindow) => {
93+
const checker = new spellChecker.Spellchecker();
94+
95+
let options = [];
96+
if (defaultActions.misspelledWord) {
97+
options = options.concat(
98+
checker
99+
.getCorrectionsForMisspelling(defaultActions.misspelledWord)
100+
.map(word => {
101+
return {
102+
label: word,
103+
click: () => {
104+
browserWindow.webContents.insertText(word);
105+
}
106+
};
107+
})
108+
.slice(0, 5)
109+
);
110+
}
111+
return options;
112+
}
91113
});
92114
return window;
93115
};

electron_app/yarn.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3984,6 +3984,11 @@ [email protected], nan@^2.11.0, nan@^2.12.1:
39843984
version "2.14.0"
39853985
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c"
39863986

3987+
nan@^2.14.0:
3988+
version "2.14.1"
3989+
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.1.tgz#d7be34dfa3105b91494c3147089315eff8874b01"
3990+
integrity sha512-isWHgVjnFjh2x2yuJ/tj3JbwoHu3UC2dX5G/88Cm24yB6YopVgxvBObDY7n5xW6ExmFhJpSEQqFPvq9zaXc8Jw==
3991+
39873992
nanomatch@^1.2.9:
39883993
version "1.2.13"
39893994
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
@@ -5408,6 +5413,14 @@ speedometer@~0.1.2:
54085413
resolved "https://registry.yarnpkg.com/speedometer/-/speedometer-0.1.4.tgz#9876dbd2a169d3115402d48e6ea6329c8816a50d"
54095414
integrity sha1-mHbb0qFp0xFUAtSObqYynIgWpQ0=
54105415

5416+
spellchecker@^3.7.0:
5417+
version "3.7.0"
5418+
resolved "https://registry.yarnpkg.com/spellchecker/-/spellchecker-3.7.0.tgz#d63e6fd612352b0108e7bbf942f271665ff63c8b"
5419+
integrity sha512-saQT4BR9nivbK70s0YjyIlSbZzO6bfWRULcGL2JU7fi7wotOnWl70P0QoUwwLywNQJQ47osgCo6GmOlqzRTxbQ==
5420+
dependencies:
5421+
any-promise "^1.3.0"
5422+
nan "^2.14.0"
5423+
54115424
split-string@^3.0.1, split-string@^3.0.2:
54125425
version "3.1.0"
54135426
resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2"

email_composer/src/utils/electronInterface.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { labels } from './systemLabels';
22
const electron = window.require('electron');
3-
const { remote, ipcRenderer } = electron;
3+
const spellChecker = window.require('spellchecker');
4+
const { remote, ipcRenderer, webFrame } = electron;
45
const composerId = remote.getCurrentWindow().id;
56
const globalManager = remote.require('./src/globalManager');
67
export const getAlicePort = remote.require('./src/aliceManager').getPort;
@@ -33,3 +34,13 @@ export const LabelType = labels;
3334
export const sendEventToMailbox = (name, params) => {
3435
ipcRenderer.send(name, params);
3536
};
37+
38+
webFrame.setSpellCheckProvider(mySettings.language, {
39+
spellCheck(words, callback) {
40+
const checker = new spellChecker.Spellchecker();
41+
const misspelled = words.filter(x => {
42+
return checker.isMisspelled(x);
43+
});
44+
callback(misspelled);
45+
}
46+
});

0 commit comments

Comments
 (0)