mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-27 15:04:31 +08:00
feat(contextual-menus): Basic cut/copy/paste for all inputs—#161
This commit is contained in:
parent
6bee127134
commit
50576e59e3
2 changed files with 28 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue