mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-11 10:12:00 +08:00
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:
parent
9dda306d1f
commit
ea67bec9d9
1 changed files with 3 additions and 19 deletions
|
@ -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) =>
|
||||
|
|
Loading…
Reference in a new issue