-
Notifications
You must be signed in to change notification settings - Fork 15.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for spell checking #942
Conversation
Is it also possible to enable spellcheck inside webview tag content? |
You can enable it in the preload script of |
Thanks @zcbenz |
I don't manage to get this spellchecker working, even after reading the documentation about it and trying to understand what is a provider. Maybe one of you can explain with the simple example below. Also, I precise that am new to electron. For the example I am simply using https://github.com/atom/electron/blob/master/docs/tutorial/quick-start.md with an input element in index.html file. If I add it to main.js then when I try to run this electron app I will have : Error: Cannot find module 'web-frame' Beside this, on the renderer, do I have to make a call of this spellCheck function and changed the result accordingly to the returned value ? As you can see, I obviously lack of knowledge about electron and web application coding. EDIT : I was actually using this code well, since if I log the text in the console it output the text as it should. Problem is this line return !(require('spellchecker').isMisspelled(text)); which deals with spellchecker module crashes the total application with this message : "inspected target disconnected. Once it reloads we will attach to it automatically." I am running it on ubuntu 14.04 and I have hanspell installed. |
@aggregatejeff You have to do it yourself via the Context Menu API :( |
Thanks @paulcbetts! At least a) I'll stop banging my head against a wall, and b) a work-around is possible. |
@francoisMinette how did you solve the |
Hi, I did not solve it. I was learning about electron at the time, but I
|
@paulcbetts I finally got around to working on this, and have made some progress. I can get spellchecker to check a word, return suggestions, and populate the context menu with those suggestions. But I'm stumped on how to pass back to spellchecker the word that was clicked on, and then how to tell the webview what to replace. The latter seems like it can be solved through .replace(text), but getting the word clicked upon doesn't seem very simple. Do you know if there's a way to do this through electron, or do I need to write some custom javascript? I'm happy to share my results when it works, and any help would be greatly appreciated. |
So... I build this. It took some digging, but here's what I found:
I combined the scripts for spellchecking and context menu building into one file for ease of use:
|
@aggregatejeff So I've got the set-up that you've outlined here working, but I've noticed an issue and I was wondering if you (or someone else) had come up with a workaround. When the spellcheck function runs, it builds out the menu. If you then right-click somewhere in the text area that is whitespace, it still shows the menu with the list of misspelled words, but selecting one won't trigger the replacement (since you did not click on top of the misspelled word). Conversely, if you right-click on a misspelled word twice, the replacement menu will be empty the second time. This all has to do with the mismatch between when the spell-checker runs and when the pop-up menu is shown. I'm not enough of a javascript expert to figure out how to reconcile those two states. Ideally it seems like you would want to query if there is currently a misspelled word under the mouse when creating the pop-up menu and build the context menu if there is. |
For people brought here by google or elsewhere and looking for a simple solution to this, electron-editor-context-menu fixes the bugs pointed out by @crimsoncor and is based on the gist provided by @aggregatejeff . It's been working for me thus far. |
I fixed this issue by figuring out how to get the currently highlighted word on a right-click event and then generating the spell-check menu directly in the eventListener function. Meant to come back and add a note on that and it just slipped my mind. But it has been working great. |
And my apologies for not noticing the question, but as suggested, I continued to iterate and improved the above using getSelection(), and a few other tweaks. |
Is there any plans to improve the context menu stuff? Would be nice if we didn't have to implement that ourselves. |
It's very surprising this hasn't been implemented already. Any updates on native spell checking functionality without manually implementing context menu behavior? |
This PR adds an
webFrame.setSpellCheckProvider
API to set a provider for spell checking in input fields and text areas.Example:
Fixes #724.