[kotlin] J2K copy-paste: commit document correctly

KTIJ-28714
IJ-CR-150614

(cherry picked from commit 406f144ef15f81becf35a59bb3d844885d959683)

GitOrigin-RevId: f60767b9d805b84eeb7c46038a05680113019d99
This commit is contained in:
Alexey Belkov
2024-12-04 01:47:39 +04:00
committed by intellij-monorepo-bot
parent fe5b7f66f2
commit 143ae41304
2 changed files with 2 additions and 4 deletions

View File

@@ -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<FqName>
): TextRange? {
if (referenceData.isEmpty() && importsToAdd.isEmpty()) return bounds
PsiDocumentManager.getInstance(project).commitDocument(targetData.document)
val rangeMarker = targetData.document.createRangeMarker(bounds)
rangeMarker.isGreedyToLeft = true

View File

@@ -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<FqName>): TextRange? {
if (importsToAdd.isEmpty()) return bounds
PsiDocumentManager.getInstance(project).commitDocument(targetData.document)
val rangeMarker = targetData.document.createRangeMarker(bounds).apply {
isGreedyToLeft = true
isGreedyToRight = true