MCPcopy Create free account
hub / github.com/adobe/react-spectrum / writeClipboardData

Function writeClipboardData

packages/@react-spectrum/ai/src/TokenField.tsx:256–273  ·  view source on GitHub ↗
(e: ClipboardEvent | DragEvent)

Source from the content-addressed store, hash-verified

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);

Callers

nothing calls this directly

Calls 5

getSelectionFunction · 0.85
applyFunction · 0.85
sliceMethod · 0.80
replaceRangeMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected