diff --git a/python/src/com/jetbrains/python/formatter/PyFromImportPostFormatProcessor.java b/python/src/com/jetbrains/python/formatter/PyFromImportPostFormatProcessor.java index 0b1505386aa5eca20d2fa614d0e96fe096099fed..5a129eb06bcc9a11b3a13e8d5dd52733d3dcb82c 100644 --- a/python/src/com/jetbrains/python/formatter/PyFromImportPostFormatProcessor.java +++ b/python/src/com/jetbrains/python/formatter/PyFromImportPostFormatProcessor.java @@ -155,9 +155,12 @@ public class PyFromImportPostFormatProcessor implements PostFormatProcessor { return newFromImport; } else { + final int oldLength = fromImport.getTextLength(); // Add only trailing comma - final PsiElement comma = fromImport.addAfter(generator.createComma().getPsi(), allNames[allNames.length - 1]); - codeStyleManager.reformat(comma); + fromImport.addAfter(generator.createComma().getPsi(), allNames[allNames.length - 1]); + // Adjust spaces around the comma if necessary + codeStyleManager.reformat(fromImport, true); + myHelper.updateResultRange(oldLength, fromImport.getTextLength()); return fromImport; } } diff --git a/python/src/com/jetbrains/python/formatter/PyPreFormatProcessor.java b/python/src/com/jetbrains/python/formatter/PyPreFormatProcessor.java index 43600a4a2937f5b284a6cea24ffc54e1003af01e..78cc3ed9a2fcebc500a983441bd3e0f5c58e82f3 100644 --- a/python/src/com/jetbrains/python/formatter/PyPreFormatProcessor.java +++ b/python/src/com/jetbrains/python/formatter/PyPreFormatProcessor.java @@ -82,16 +82,10 @@ public class PyPreFormatProcessor implements PreFormatProcessor { final PsiDocumentManager manager = PsiDocumentManager.getInstance(myProject); final Document document = manager.getDocument(element.getContainingFile()); if (document != null) { - manager.doPostponedOperationsAndUnblockDocument(document); - try { - // collect all comments - element.accept(this); - for (Couple<PsiComment> pair : myCommentReplacements) { - pair.getFirst().replace(pair.getSecond()); - } - } - finally { - manager.commitDocument(document); + // collect all comments + element.accept(this); + for (Couple<PsiComment> pair : myCommentReplacements) { + pair.getFirst().replace(pair.getSecond()); } } return TextRange.create(range.getStartOffset(), range.getEndOffset() + myDelta);