Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Instructions unclear #13

Open
04fsnape opened this issue May 29, 2019 · 0 comments
Open

Instructions unclear #13

04fsnape opened this issue May 29, 2019 · 0 comments

Comments

@04fsnape
Copy link

Hello,

I don't understand your installation instructions. I installed it with npm install electron-editor-context-menu, but how do I actually put it in my electron app? You put this code in your readme but don't explain where it goes:

// In the renderer process:
var remote = require('electron').remote;
// `remote.require` since `Menu` is a main-process module.
var buildEditorContextMenu = remote.require('electron-editor-context-menu');

window.addEventListener('contextmenu', function(e) {
  // Only show the context menu in text editors.
  if (!e.target.closest('textarea, input, [contenteditable="true"]')) return;

  var menu = buildEditorContextMenu();

  // The 'contextmenu' event is emitted after 'selectionchange' has fired but possibly before the
  // visible selection has changed. Try to wait to show the menu until after that, otherwise the
  // visible selection will update after the menu dismisses and look weird.
  setTimeout(function() {
    menu.popup(remote.getCurrentWindow());
  }, 30);
});

Is this meant to go in my electron main.js file, or am I meant to call it as a script from my html file?

Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant