@@ -39,6 +39,7 @@ import {
3939 transformCoordToPoint ,
4040 getCellRangeValue ,
4141 getCellValue ,
42+ shouldHandleClipboardEvent ,
4243} from "./util" ;
4344import "./Spreadsheet.css" ;
4445
@@ -286,42 +287,51 @@ const Spreadsheet = <CellType extends Types.CellBase>(
286287 [ store ]
287288 ) ;
288289
289- const isFocused = React . useCallback ( ( ) => {
290- const root = rootRef . current ;
291- const { activeElement } = document ;
292-
293- return mode === "view" && root
294- ? root === activeElement || root . contains ( activeElement )
295- : false ;
296- } , [ rootRef , mode ] ) ;
297-
298290 const handleCut = React . useCallback (
299291 ( event : ClipboardEvent ) => {
300- if ( isFocused ( ) ) {
292+ if (
293+ shouldHandleClipboardEvent (
294+ document . activeElement ,
295+ rootRef . current ,
296+ mode
297+ )
298+ ) {
301299 event . preventDefault ( ) ;
302300 event . stopPropagation ( ) ;
303301 clip ( event ) ;
304302 cut ( ) ;
305303 }
306304 } ,
307- [ isFocused , clip , cut ]
305+ [ mode , clip , cut ]
308306 ) ;
309307
310308 const handleCopy = React . useCallback (
311309 ( event : ClipboardEvent ) => {
312- if ( isFocused ( ) ) {
310+ if (
311+ shouldHandleClipboardEvent (
312+ document . activeElement ,
313+ rootRef . current ,
314+ mode
315+ )
316+ ) {
313317 event . preventDefault ( ) ;
314318 event . stopPropagation ( ) ;
315319 clip ( event ) ;
316320 copy ( ) ;
317321 }
318322 } ,
319- [ isFocused , clip , copy ]
323+ [ mode , clip , copy ]
320324 ) ;
321325
322326 const handlePaste = React . useCallback (
323- async ( event : ClipboardEvent ) => {
324- if ( mode === "view" && isFocused ( ) ) {
327+ ( event : ClipboardEvent ) => {
328+ if (
329+ shouldHandleClipboardEvent (
330+ document . activeElement ,
331+ rootRef . current ,
332+ mode
333+ )
334+ ) {
325335 event . preventDefault ( ) ;
326336 event . stopPropagation ( ) ;
327337 if ( event . clipboardData ) {
@@ -330,7 +340,7 @@ const Spreadsheet = <CellType extends Types.CellBase>(
330340 }
331341 }
332342 } ,
333- [ mode , isFocused , paste ]
343+ [ mode , paste ]
334344 ) ;
335345
336346 const handleKeyDown = React . useCallback (
0 commit comments