From 143ae413043e44f360a420f9f3c546a2fa10c5ec Mon Sep 17 00:00:00 2001 From: Alexey Belkov Date: Wed, 4 Dec 2024 01:47:39 +0400 Subject: [PATCH] [kotlin] J2K copy-paste: commit document correctly KTIJ-28714 IJ-CR-150614 (cherry picked from commit 406f144ef15f81becf35a59bb3d844885d959683) GitOrigin-RevId: f60767b9d805b84eeb7c46038a05680113019d99 --- .../jetbrains/kotlin/j2k/copyPaste/K1J2KCopyPasteConverter.kt | 3 +-- .../kotlin/j2k/k2/copyPaste/K2J2KCopyPasteConverter.kt | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/kotlin/j2k/k1.new/src/org/jetbrains/kotlin/j2k/copyPaste/K1J2KCopyPasteConverter.kt b/plugins/kotlin/j2k/k1.new/src/org/jetbrains/kotlin/j2k/copyPaste/K1J2KCopyPasteConverter.kt index 17baff5600b9..05b4da3112a8 100644 --- a/plugins/kotlin/j2k/k1.new/src/org/jetbrains/kotlin/j2k/copyPaste/K1J2KCopyPasteConverter.kt +++ b/plugins/kotlin/j2k/k1.new/src/org/jetbrains/kotlin/j2k/copyPaste/K1J2KCopyPasteConverter.kt @@ -52,10 +52,10 @@ class K1J2KCopyPasteConverter( runWriteAction { targetData.document.replaceString(targetData.bounds.startOffset, targetData.bounds.endOffset, changedText) editor.caretModel.moveToOffset(endOffsetAfterReplace) + PsiDocumentManager.getInstance(project).commitDocument(targetData.document) } val newBounds = restoreReferencesAndInsertImports(boundsAfterReplace, referenceData, importsToAdd) - PsiDocumentManager.getInstance(project).commitDocument(targetData.document) runPostProcessing(project, targetData.file, newBounds, converterContext, j2kKind) } @@ -131,7 +131,6 @@ class K1J2KCopyPasteConverter( importsToAdd: Collection ): TextRange? { if (referenceData.isEmpty() && importsToAdd.isEmpty()) return bounds - PsiDocumentManager.getInstance(project).commitDocument(targetData.document) val rangeMarker = targetData.document.createRangeMarker(bounds) rangeMarker.isGreedyToLeft = true diff --git a/plugins/kotlin/j2k/k2/src/org/jetbrains/kotlin/j2k/k2/copyPaste/K2J2KCopyPasteConverter.kt b/plugins/kotlin/j2k/k2/src/org/jetbrains/kotlin/j2k/k2/copyPaste/K2J2KCopyPasteConverter.kt index 937ffdbbf1c0..95c2de170e69 100644 --- a/plugins/kotlin/j2k/k2/src/org/jetbrains/kotlin/j2k/k2/copyPaste/K2J2KCopyPasteConverter.kt +++ b/plugins/kotlin/j2k/k2/src/org/jetbrains/kotlin/j2k/k2/copyPaste/K2J2KCopyPasteConverter.kt @@ -51,10 +51,10 @@ internal class K2J2KCopyPasteConverter( runWriteAction { targetData.document.replaceString(targetData.bounds.startOffset, targetData.bounds.endOffset, changedText) editor.caretModel.moveToOffset(endOffsetAfterReplace) + PsiDocumentManager.getInstance(project).commitDocument(targetData.document) } val newBounds = insertImports(boundsAfterReplace, importsToAdd) - PsiDocumentManager.getInstance(project).commitDocument(targetData.document) runPostProcessing(project, targetData.file, newBounds, converterContext, Kind.K2) } @@ -77,7 +77,6 @@ internal class K2J2KCopyPasteConverter( private fun insertImports(bounds: TextRange, importsToAdd: Collection): TextRange? { if (importsToAdd.isEmpty()) return bounds - PsiDocumentManager.getInstance(project).commitDocument(targetData.document) val rangeMarker = targetData.document.createRangeMarker(bounds).apply { isGreedyToLeft = true isGreedyToRight = true