From 1ddbac1d2ee8a9c6e22d2b2a6b979c9dc69b6fef Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Sat, 20 Dec 2025 16:26:30 -0800 Subject: [PATCH] fix(code): cmd-z after refocus should not clear subblock (#2503) --- .../components/sub-block/components/code/code.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/code/code.tsx b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/code/code.tsx index 231b00013..cd08adf88 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/code/code.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/code/code.tsx @@ -214,6 +214,7 @@ export function Code({ const handleStreamStartRef = useRef<() => void>(() => {}) const handleGeneratedContentRef = useRef<(generatedCode: string) => void>(() => {}) const handleStreamChunkRef = useRef<(chunk: string) => void>(() => {}) + const hasEditedSinceFocusRef = useRef(false) // Custom hooks const accessiblePrefixes = useAccessibleReferencePrefixes(blockId) @@ -504,6 +505,7 @@ export function Code({ setCode(newValue) setStoreValue(newValue) + hasEditedSinceFocusRef.current = true const newCursorPosition = dropPosition + 1 setCursorPosition(newCursorPosition) @@ -533,6 +535,7 @@ export function Code({ if (!isPreview && !readOnly) { setCode(newValue) emitTagSelection(newValue) + hasEditedSinceFocusRef.current = true } setShowTags(false) setActiveSourceBlockId(null) @@ -550,6 +553,7 @@ export function Code({ if (!isPreview && !readOnly) { setCode(newValue) emitTagSelection(newValue) + hasEditedSinceFocusRef.current = true } setShowEnvVars(false) @@ -741,6 +745,7 @@ export function Code({ value={code} onValueChange={(newCode) => { if (!isAiStreaming && !isPreview && !disabled && !readOnly) { + hasEditedSinceFocusRef.current = true setCode(newCode) setStoreValue(newCode) @@ -769,6 +774,12 @@ export function Code({ if (isAiStreaming) { e.preventDefault() } + if (e.key === 'z' && (e.metaKey || e.ctrlKey) && !hasEditedSinceFocusRef.current) { + e.preventDefault() + } + }} + onFocus={() => { + hasEditedSinceFocusRef.current = false }} highlight={createHighlightFunction(effectiveLanguage, shouldHighlightReference)} {...getCodeEditorProps({ isStreaming: isAiStreaming, isPreview, disabled })}