From 37ebe41526ad5f7fbc88f0c5091e55f137dbd5fe Mon Sep 17 00:00:00 2001 From: Akhileshrangani4 Date: Wed, 1 Jan 2025 08:15:53 -0500 Subject: [PATCH] fix: ctrl/cmd + z with applied code --- frontend/components/editor/index.tsx | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/frontend/components/editor/index.tsx b/frontend/components/editor/index.tsx index c992d61..4904fdb 100644 --- a/frontend/components/editor/index.tsx +++ b/frontend/components/editor/index.tsx @@ -387,9 +387,16 @@ export default function CodeEditor({ (mergedCode: string, originalCode: string) => { if (!editorRef) return + const model = editorRef.getModel() + if (!model) return // Store original content + ;(model as any).originalContent = originalCode + + // Calculate the full range of the document + const fullRange = model.getFullModelRange() + + // Create decorations before applying the edit const originalLines = originalCode.split("\n") const mergedLines = mergedCode.split("\n") - const decorations: monaco.editor.IModelDeltaDecoration[] = [] for ( @@ -410,14 +417,16 @@ export default function CodeEditor({ } } - // Store original content in the model - const model = editorRef.getModel() - if (model) { - ;(model as any).originalContent = originalCode - } - editorRef.setValue(mergedCode) + // Execute the edit operation + editorRef.executeEdits("apply-code", [ + { + range: fullRange, + text: mergedCode, + forceMoveMarkers: true, + }, + ]) - // Apply decorations + // Apply decorations after the edit const newDecorations = editorRef.createDecorationsCollection(decorations) setMergeDecorationsCollection(newDecorations) },