@@ -214,6 +214,7 @@ export function Code({
214214 const handleStreamStartRef = useRef < ( ) => void > ( ( ) => { } )
215215 const handleGeneratedContentRef = useRef < ( generatedCode : string ) => void > ( ( ) => { } )
216216 const handleStreamChunkRef = useRef < ( chunk : string ) => void > ( ( ) => { } )
217+ const hasEditedSinceFocusRef = useRef ( false )
217218
218219 // Custom hooks
219220 const accessiblePrefixes = useAccessibleReferencePrefixes ( blockId )
@@ -504,6 +505,7 @@ export function Code({
504505
505506 setCode ( newValue )
506507 setStoreValue ( newValue )
508+ hasEditedSinceFocusRef . current = true
507509 const newCursorPosition = dropPosition + 1
508510 setCursorPosition ( newCursorPosition )
509511
@@ -533,6 +535,7 @@ export function Code({
533535 if ( ! isPreview && ! readOnly ) {
534536 setCode ( newValue )
535537 emitTagSelection ( newValue )
538+ hasEditedSinceFocusRef . current = true
536539 }
537540 setShowTags ( false )
538541 setActiveSourceBlockId ( null )
@@ -550,6 +553,7 @@ export function Code({
550553 if ( ! isPreview && ! readOnly ) {
551554 setCode ( newValue )
552555 emitTagSelection ( newValue )
556+ hasEditedSinceFocusRef . current = true
553557 }
554558 setShowEnvVars ( false )
555559
@@ -741,6 +745,7 @@ export function Code({
741745 value = { code }
742746 onValueChange = { ( newCode ) => {
743747 if ( ! isAiStreaming && ! isPreview && ! disabled && ! readOnly ) {
748+ hasEditedSinceFocusRef . current = true
744749 setCode ( newCode )
745750 setStoreValue ( newCode )
746751
@@ -769,6 +774,12 @@ export function Code({
769774 if ( isAiStreaming ) {
770775 e . preventDefault ( )
771776 }
777+ if ( e . key === 'z' && ( e . metaKey || e . ctrlKey ) && ! hasEditedSinceFocusRef . current ) {
778+ e . preventDefault ( )
779+ }
780+ } }
781+ onFocus = { ( ) => {
782+ hasEditedSinceFocusRef . current = false
772783 } }
773784 highlight = { createHighlightFunction ( effectiveLanguage , shouldHighlightReference ) }
774785 { ...getCodeEditorProps ( { isStreaming : isAiStreaming , isPreview, disabled } ) }
0 commit comments