@@ -145,18 +145,32 @@ export function useCopyToClipboard() {
145145 const copyToClipboard = React . useCallback ( ( value ) => {
146146 const handleCopy = async ( ) => {
147147 try {
148- if ( navigator ?. clipboard ?. writeText ) {
148+ // ClipboardItem API for multiple formats
149+ if ( typeof value === 'object' && value !== null && window . ClipboardItem ) {
150+ const items = { } ;
151+ if ( value . plain ) {
152+ items [ "text/plain" ] = new Blob ( [ value . plain ] , { type : "text/plain" } ) ;
153+ }
154+ if ( value . html ) {
155+ items [ "text/html" ] = new Blob ( [ value . html ] , { type : "text/html" } ) ;
156+ }
157+ if ( value . markdown ) {
158+ items [ "text/markdown" ] = new Blob ( [ value . markdown ] , { type : "text/markdown" } ) ;
159+ }
160+ const clipboardItem = new ClipboardItem ( items ) ;
161+ await navigator . clipboard . write ( [ clipboardItem ] ) ;
162+ setState ( value . plain || value . html || value . markdown ) ;
163+ } else if ( navigator ?. clipboard ?. writeText ) {
149164 await navigator . clipboard . writeText ( value ) ;
150165 setState ( value ) ;
151166 } else {
152167 throw new Error ( "writeText not supported" ) ;
153168 }
154169 } catch ( e ) {
155- oldSchoolCopy ( value ) ;
156- setState ( value ) ;
170+ oldSchoolCopy ( typeof value === 'object' ? value . plain : value ) ;
171+ setState ( typeof value === 'object' ? value . plain : value ) ;
157172 }
158173 } ;
159-
160174 handleCopy ( ) ;
161175 } , [ ] ) ;
162176
@@ -653,10 +667,27 @@ export function useLocalStorage(key, initialValue) {
653667
654668export function useLockBodyScroll ( ) {
655669 React . useLayoutEffect ( ( ) => {
656- const originalStyle = window . getComputedStyle ( document . body ) . overflow ;
670+ // Preserve the current scroll position
671+ const scrollY = window . scrollY || window . pageYOffset ;
672+
673+ // Save original inline styles so we can restore them
674+ const originalOverflow = window . getComputedStyle ( document . body ) . overflow ;
675+ const originalPosition = document . body . style . position ;
676+ const originalTop = document . body . style . top ;
677+
678+ // Lock the body scroll by fixing position and offsetting by the scroll
657679 document . body . style . overflow = "hidden" ;
680+ document . body . style . position = "fixed" ;
681+ document . body . style . top = `-${ scrollY } px` ;
682+
658683 return ( ) => {
659- document . body . style . overflow = originalStyle ;
684+ // Restore original inline styles
685+ document . body . style . position = originalPosition ;
686+ document . body . style . top = originalTop ;
687+ document . body . style . overflow = originalOverflow ;
688+
689+ // Restore the scroll position
690+ window . scrollTo ( 0 , scrollY ) ;
660691 } ;
661692 } , [ ] ) ;
662693}
0 commit comments