diff --git a/preload.js b/preload.js
index 91feecb340..8d9fde4c1d 100644
--- a/preload.js
+++ b/preload.js
@@ -46,17 +46,7 @@
}
resetSelection();
- // Reset the selection when clicking around, before the spell-checker runs and the context menu shows.
- window.addEventListener('mousedown', resetSelection);
-
- // The spell-checker runs when the user clicks on text and before the 'contextmenu' event fires.
- // Thus, we may retrieve spell-checking suggestions to put in the menu just before it shows.
- webFrame.setSpellCheckProvider(
- 'en-US',
- // Not sure what this parameter (`autoCorrectWord`) does: https://github.com/atom/electron/issues/4371
- // The documentation for `webFrame.setSpellCheckProvider` passes `true` so we do too.
- true,
- new SpellCheckProvider('en-US').on('misspelling', function(suggestions) {
+ window.spellChecker = new SpellCheckProvider(window.config.locale).on('misspelling', function(suggestions) {
// Prime the context menu with spelling suggestions _if_ the user has selected text. Electron
// may sometimes re-run the spell-check provider for an outdated selection e.g. if the user
// right-clicks some misspelled text and then an image.
@@ -65,7 +55,21 @@
// Take the first three suggestions if any.
selection.spellingSuggestions = suggestions.slice(0, 3);
}
- }));
+ });
+
+ // Reset the selection when clicking around, before the spell-checker runs and the context menu shows.
+ window.addEventListener('mousedown', resetSelection);
+
+ // The spell-checker runs when the user clicks on text and before the 'contextmenu' event fires.
+ // Thus, we may retrieve spell-checking suggestions to put in the menu just before it shows.
+
+ webFrame.setSpellCheckProvider(
+ 'en-US',
+ // Not sure what this parameter (`autoCorrectWord`) does: https://github.com/atom/electron/issues/4371
+ // The documentation for `webFrame.setSpellCheckProvider` passes `true` so we do too.
+ true,
+ spellChecker
+ );
window.addEventListener('contextmenu', function(e) {
// Only show the context menu in text editors.
diff --git a/test/index.html b/test/index.html
index 7cc4b65f96..346d37601b 100644
--- a/test/index.html
+++ b/test/index.html
@@ -654,6 +654,7 @@
+
diff --git a/test/spellcheck_test.js b/test/spellcheck_test.js
new file mode 100644
index 0000000000..3a52e4472c
--- /dev/null
+++ b/test/spellcheck_test.js
@@ -0,0 +1,10 @@
+/*
+ * vim: ts=4:sw=4:expandtab
+ */
+
+describe('spellChecker', function() {
+ it('should work', function() {
+ assert(window.spellChecker.spellCheck('correct'));
+ assert(!window.spellChecker.spellCheck('fhqwgads'));
+ });
+});