feat(contextual-menus): Basic cut/copy/paste for all inputs—#161

This commit is contained in:
Ben Gotow 2015-10-29 21:24:51 -07:00
parent 6bee127134
commit 50576e59e3
2 changed files with 28 additions and 0 deletions

View file

@ -115,6 +115,8 @@ class MessageStore extends NylasStore
@_fetchFromCache()
_onFocusChanged: (change) =>
return unless change.impactsCollection('thread')
# This implements a debounce that fires on the leading and trailing edge.
#
# If we haven't changed focus in the last 100ms, do it immediately. This means

View file

@ -105,6 +105,8 @@ class WindowEventHandler
@subscribe $(document), 'click', 'a', @openLink
@subscribe $(document), 'contextmenu', 'input', @openContextualMenuForInput
# Prevent form submits from changing the current window's URL
@subscribe $(document), 'submit', 'form', (e) -> e.preventDefault()
@ -160,6 +162,30 @@ class WindowEventHandler
return
openContextualMenuForInput: (event) ->
event.preventDefault()
hasSelectedText = event.target.selectionStart isnt event.target.selectionEnd
remote = require('remote')
Menu = remote.require('menu')
MenuItem = remote.require('menu-item')
menu = new Menu()
menu.append(new MenuItem({
label: 'Cut'
enabled: hasSelectedText
click: => document.execCommand('cut')
}))
menu.append(new MenuItem({
label: 'Copy'
enabled: hasSelectedText
click: => document.execCommand('copy')
}))
menu.append(new MenuItem({
label: 'Paste',
click: => document.execCommand('paste')
}))
menu.popup(remote.getCurrentWindow())
eachTabIndexedElement: (callback) ->
for element in $('[tabindex]')
element = $(element)