In Electron, right-clicking in text editors does⌠nothing.
This module enables the menu you'd expect, with optional
spell-checker integration.
Installation
npm install electron-editor-context-menu --save
Usage
var remote = require('electron').remote;
var buildEditorContextMenu = remote.require('electron-editor-context-menu');
window.addEventListener('contextmenu', function(e) {
if (!e.target.closest('textarea, input, [contenteditable="true"]')) return;
var menu = buildEditorContextMenu();
setTimeout(function() {
menu.popup(remote.getCurrentWindow());
}, 30);
});
Spell-checker integration
Show spelling suggestions by passing a selection object when building the menu:
var selection = {
isMisspelled: true,
spellingSuggestions: [
'men',
'mean',
'menu'
]
};
var menu = buildEditorContextMenu(selection);
Get these suggestions when your spell-check provider runs
âElectron will poll it immediately before the 'contextmenu' event fires.
For a complete example using electron-spell-check-provider, see
here.
Credits
Created by Jeff Wear.
Thanks to https://github.com/atom/electron/pull/942#issuecomment-171445954 for
the initial sketch of this.
Copyright and License
Copyright 2016 Mixmax, Inc., licensed under the MIT License.
Release History
- 1.1.1 Fix compatibility with electron-builder
- 1.1.0 Add the ability to customize the main template and the suggestions template.
- 1.0.0 Initial release.