aboutsummaryrefslogtreecommitdiffstats
path: root/src/webview/contextMenu.js
blob: 7ab60d251b12868ba170983b0f85e57b0d324762 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { remote } from "electron";
import { ContextMenuBuilder, ContextMenuListener } from "electron-spellchecker";

const webContents = remote.getCurrentWebContents();

export default async function setupContextMenu(handler) {
  const processMenu = (menu, menuInfo) => {
    if (
      menuInfo.editFlags.canPaste &&
      !menuInfo.linkText &&
      !menuInfo.hasImageContents
    ) {
      menu.insert(
        3,
        new remote.MenuItem({
          label: "Paste as plain text",
          accelerator: "CommandOrControl+Shift+V",
          click: () => webContents.pasteAndMatchStyle()
        })
      );
    }
    return menu;
  };

  const contextMenuBuilder = new ContextMenuBuilder(
    handler,
    null,
    true,
    processMenu
  );
  // eslint-disable-next-line no-new
  new ContextMenuListener(info => {
    contextMenuBuilder.showPopupMenu(info);
  });
}