diff --git a/src/components/useRawModeWithFlush.ts b/src/components/useRawModeWithFlush.ts index 4ef7bb42..b6d46e7a 100644 --- a/src/components/useRawModeWithFlush.ts +++ b/src/components/useRawModeWithFlush.ts @@ -246,17 +246,21 @@ function useSyncRawModeContentOverride({ rawSourceContentRef: React.MutableRefObject setRawModeContentOverride: React.Dispatch> }) { - const syncRawModeContentOverride = (current: PendingRawExitContent | null) => { + const syncRawModeContentOverride = ( + current: PendingRawExitContent | null, + nextContent: string, + ) => { if (!current) return current - if (current.path !== activeTabPath || current.content === activeTabContent) return current - return { path: activeTabPath, content: activeTabContent } + if (current.path !== activeTabPath || current.content === nextContent) return current + return { path: activeTabPath, content: nextContent } } useLayoutEffect(() => { if (!activeTabPath || activeTabContent === null) return if (rawSourceContentRef.current === null || activeTabContent === rawSourceContentRef.current) return + const nextContent = activeTabContent - setRawModeContentOverride(syncRawModeContentOverride) + setRawModeContentOverride((current) => syncRawModeContentOverride(current, nextContent)) }, [activeTabContent, activeTabPath, rawSourceContentRef, setRawModeContentOverride]) }