mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-10-06 11:16:10 +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()
|
@_fetchFromCache()
|
||||||
|
|
||||||
_onFocusChanged: (change) =>
|
_onFocusChanged: (change) =>
|
||||||
|
return unless change.impactsCollection('thread')
|
||||||
|
|
||||||
# This implements a debounce that fires on the leading and trailing edge.
|
# 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
|
# 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), 'click', 'a', @openLink
|
||||||
|
|
||||||
|
@subscribe $(document), 'contextmenu', 'input', @openContextualMenuForInput
|
||||||
|
|
||||||
# Prevent form submits from changing the current window's URL
|
# Prevent form submits from changing the current window's URL
|
||||||
@subscribe $(document), 'submit', 'form', (e) -> e.preventDefault()
|
@subscribe $(document), 'submit', 'form', (e) -> e.preventDefault()
|
||||||
|
|
||||||
|
@ -160,6 +162,30 @@ class WindowEventHandler
|
||||||
|
|
||||||
return
|
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) ->
|
eachTabIndexedElement: (callback) ->
|
||||||
for element in $('[tabindex]')
|
for element in $('[tabindex]')
|
||||||
element = $(element)
|
element = $(element)
|
||||||
|
|
Loading…
Add table
Reference in a new issue