fix: ctrl/cmd + z with applied code

This commit is contained in:
Akhileshrangani4 2025-01-01 08:15:53 -05:00
parent a41cdff55f
commit 274c945fac

View File

@ -387,9 +387,16 @@ export default function CodeEditor({
(mergedCode: string, originalCode: string) => { (mergedCode: string, originalCode: string) => {
if (!editorRef) return 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 originalLines = originalCode.split("\n")
const mergedLines = mergedCode.split("\n") const mergedLines = mergedCode.split("\n")
const decorations: monaco.editor.IModelDeltaDecoration[] = [] const decorations: monaco.editor.IModelDeltaDecoration[] = []
for ( for (
@ -410,14 +417,16 @@ export default function CodeEditor({
} }
} }
// Store original content in the model // Execute the edit operation
const model = editorRef.getModel() editorRef.executeEdits("apply-code", [
if (model) { {
;(model as any).originalContent = originalCode range: fullRange,
} text: mergedCode,
editorRef.setValue(mergedCode) forceMoveMarkers: true,
},
])
// Apply decorations // Apply decorations after the edit
const newDecorations = editorRef.createDecorationsCollection(decorations) const newDecorations = editorRef.createDecorationsCollection(decorations)
setMergeDecorationsCollection(newDecorations) setMergeDecorationsCollection(newDecorations)
}, },