@@ -41,6 +41,10 @@ export function useCodeUndoRedo({
4141 ( ) => Boolean ( enabled && activeWorkflowId && ! isReadOnly && ! isStreaming && ! isBaselineView ) ,
4242 [ enabled , activeWorkflowId , isReadOnly , isStreaming , isBaselineView ]
4343 )
44+ const isReplaceEnabled = useMemo (
45+ ( ) => Boolean ( enabled && activeWorkflowId && ! isReadOnly && ! isBaselineView ) ,
46+ [ enabled , activeWorkflowId , isReadOnly , isBaselineView ]
47+ )
4448
4549 const lastCommittedValueRef = useRef < string > ( value ?? '' )
4650 const pendingBeforeRef = useRef < string | null > ( null )
@@ -110,7 +114,7 @@ export function useCodeUndoRedo({
110114
111115 const recordReplace = useCallback (
112116 ( nextValue : string ) => {
113- if ( ! isEnabled || isApplyingRef . current || ! activeWorkflowId ) return
117+ if ( ! isReplaceEnabled || isApplyingRef . current || ! activeWorkflowId ) return
114118
115119 if ( pendingBeforeRef . current !== null ) {
116120 commitPending ( )
@@ -137,20 +141,15 @@ export function useCodeUndoRedo({
137141 clearTimer ( )
138142 resetPending ( )
139143 } ,
140- [ activeWorkflowId , blockId , clearTimer , commitPending , isEnabled , resetPending , subBlockId ]
141- )
142-
143- const clearHistory = useCallback (
144- ( nextValue ?: string ) => {
145- if ( ! activeWorkflowId ) return
146- clearTimer ( )
147- resetPending ( )
148- useCodeUndoRedoStore . getState ( ) . clear ( activeWorkflowId , blockId , subBlockId )
149- if ( nextValue !== undefined ) {
150- lastCommittedValueRef . current = nextValue
151- }
152- } ,
153- [ activeWorkflowId , blockId , clearTimer , resetPending , subBlockId ]
144+ [
145+ activeWorkflowId ,
146+ blockId ,
147+ clearTimer ,
148+ commitPending ,
149+ isReplaceEnabled ,
150+ resetPending ,
151+ subBlockId ,
152+ ]
154153 )
155154
156155 const flushPending = useCallback ( ( ) => {
@@ -207,7 +206,7 @@ export function useCodeUndoRedo({
207206 } , [ activeWorkflowId , applyValue , blockId , flushPending , isEnabled , subBlockId ] )
208207
209208 useEffect ( ( ) => {
210- if ( isApplyingRef . current ) return
209+ if ( isApplyingRef . current || isStreaming ) return
211210
212211 const nextValue = value ?? ''
213212
@@ -221,7 +220,7 @@ export function useCodeUndoRedo({
221220 }
222221
223222 lastCommittedValueRef . current = nextValue
224- } , [ clearTimer , resetPending , value ] )
223+ } , [ clearTimer , isStreaming , resetPending , value ] )
225224
226225 useEffect ( ( ) => {
227226 return ( ) => {
@@ -231,7 +230,6 @@ export function useCodeUndoRedo({
231230
232231 return {
233232 recordChange,
234- clearHistory,
235233 recordReplace,
236234 flushPending,
237235 startSession,
0 commit comments