Hi,
I am trying to do custom handling of ‘copy’ events. This will require calling back into a port, in order to run document.execCommand('copy')
on the JS side. This must be done immediately in the event handler, in order to know that it occured as the result of user input, and not some malicious code running in the background.
I knew there was stuff added in 0.19, to better support this kind of immediate handling. The documentation for it can be found here:
Can someone provide some clarification on Note 2:
Note 2: Some actions, like uploading and downloading files, are only allowed when the JavaScript event loop is running because of user input. This is for security! So when an event occurs, we call
update
and send anyport
messages immediately, all within the same tick of the event loop. This makes it possible to handle user-instigated events in ports.
Does this apply to all event handlers in Elm? Or is it only some of the kinds of handler defined by the Handler
type? I think MayPreventDefault
is what I will be using, or possibly Custom
if I need to.
===
Stackoverflow answer here gives some good detail on custom handling of copy to the clipboard: