fix(paste): avoid code duplication, just give menu items roles

Manual implementation of clipboard behaviors was not necessary and meant that pasting images via right-click didn't go through the same code path as Cmd-V.

May fix #228, depending on the exact issue.
This commit is contained in:
Ben Gotow 2015-11-24 15:23:29 -08:00
parent 9dda306d1f
commit ea67bec9d9

View file

@ -611,31 +611,15 @@ class Contenteditable extends React.Component
@refs["toolbarController"]?.forceClose()
event.preventDefault()
selection = document.getSelection()
range = DOMUtils.Mutating.getRangeAtAndSelectWord(selection, 0)
text = range.toString()
remote = require('remote')
clipboard = require('clipboard')
Menu = remote.require('menu')
MenuItem = remote.require('menu-item')
cut = =>
clipboard.writeText(text)
DOMUtils.Mutating.applyTextInRange(range, selection, '')
copy = =>
clipboard.writeText(text)
paste = =>
DOMUtils.Mutating.applyTextInRange(range, selection, clipboard.readText())
menu = new Menu()
@_runPluginHandlersForEvent("onShowContextMenu", event, menu)
menu.append(new MenuItem({ label: 'Cut', click: cut}))
menu.append(new MenuItem({ label: 'Copy', click: copy}))
menu.append(new MenuItem({ label: 'Paste', click: paste}))
menu.append(new MenuItem({ label: 'Cut', role: 'cut'}))
menu.append(new MenuItem({ label: 'Copy', role: 'copy'}))
menu.append(new MenuItem({ label: 'Paste', role: 'paste'}))
menu.popup(remote.getCurrentWindow())
_onMouseDown: (event) =>