Prevent default context menu


#1

I’m using the electron-spell-check-provider as suggested but I’m seeing two context menus pop up – the first menu I see has exactly the same options as the application menu, and then when I click away, I can see the context menu that I wanted to appear. Any ideas how I can prevent that default application context menu from showing up?

P.S. here’s my code

const SpellCheckProvider = require("electron-spell-check-provider")
const { webFrame } = require("electron")
const provider = new SpellCheckProvider("en-US")
webFrame.setSpellCheckProvider("en-US", true, provider)

const { remote } = require("electron")
const buildEditorContextMenu = remote.require("electron-editor-context-menu")

let selection = undefined
function resetSelection() {
	selection = {
		isMisspelled: false,
		spellingSuggestions: []
	}
}
resetSelection()

window.addEventListener("mousedown", resetSelection)

provider.on("misspelling", function (suggestions) {
	if (window.getSelection().toString()) {
		selection.isMisspelled = true
		selection.spellingSuggestions = suggestions.slice(0, 3)
	}
})

window.addEventListener("contextmenu", function (e) {
	const node = (e.target as any).closest("textarea, input, [contenteditable=\"true\"]")
	if (!node) {
		return
	}
	e.preventDefault()
	e.stopPropagation()
	var menu = buildEditorContextMenu(selection)
	setTimeout(function() {
		menu.popup(remote.getCurrentWindow())
	}, 30)
})