Add spellcheck smoke test
Exposes the spellcheck provider as window.spellChecker, which allows it to be called from tests.
This commit is contained in:
parent
0ad35cc0e6
commit
33a82cc8e8
3 changed files with 27 additions and 12 deletions
28
preload.js
28
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.
|
||||
|
|
|
@ -654,6 +654,7 @@
|
|||
<script type="text/javascript" src="reliable_trigger_test.js"></script>
|
||||
<script type="text/javascript" src="backup_test.js"></script>
|
||||
<script type="text/javascript" src="i18n_test.js"></script>
|
||||
<script type="text/javascript" src="spellcheck_test.js"></script>
|
||||
|
||||
<script type="text/javascript" src="fixtures.js"></script>
|
||||
<script type="text/javascript" src="fixtures_test.js"></script>
|
||||
|
|
10
test/spellcheck_test.js
Normal file
10
test/spellcheck_test.js
Normal file
|
@ -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'));
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue