(e: ClipboardEvent | DragEvent)
| 254 | }); |
| 255 | |
| 256 | let writeClipboardData = (e: ClipboardEvent | DragEvent) => { |
| 257 | if ('clipboardData' in e) { |
| 258 | e.preventDefault(); |
| 259 | } |
| 260 | let selection = getSelection(ref.current!); |
| 261 | if (!selection) { |
| 262 | return; |
| 263 | } |
| 264 | let [start, end] = selection; |
| 265 | let slice = state.slice(start, end); |
| 266 | let dataTransfer = 'clipboardData' in e ? e.clipboardData : e.dataTransfer; |
| 267 | dataTransfer?.setData(CLIPBOARD_MIME_TYPE, JSON.stringify(slice.segments)); |
| 268 | dataTransfer?.setData('text/plain', slice.toString()); |
| 269 | |
| 270 | if (e.type === 'cut') { |
| 271 | apply(tokens => tokens.replaceRange(start, end, '', false)); |
| 272 | } |
| 273 | }; |
| 274 | |
| 275 | useEvent(ref, 'copy', writeClipboardData); |
| 276 | useEvent(ref, 'cut', writeClipboardData); |
nothing calls this directly
no test coverage detected