From 617824b1f3bcf02cd6045f6235310d8071ec0e16 Mon Sep 17 00:00:00 2001 From: peter Date: Sun, 6 Oct 2013 09:27:11 +0200 Subject: [PATCH] IDEA-113940 Enter in comment leads to inconsistent caret position --- .../editorActions/enter/EnterInLineCommentHandler.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/enter/EnterInLineCommentHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/enter/EnterInLineCommentHandler.java index ff2c801877e1..f09d79813653 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/enter/EnterInLineCommentHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/enter/EnterInLineCommentHandler.java @@ -55,8 +55,12 @@ public class EnterInLineCommentHandler extends EnterHandlerDelegateAdapter { document.insertString(caretOffset, prefix); return Result.Default; } else { + int afterPrefix = offset + prefix.length(); + if (afterPrefix < document.getTextLength() && text.charAt(afterPrefix) != ' ') { + document.insertString(afterPrefix, " "); + //caretAdvance.set(0); + } caretOffsetRef.set(offset); - caretAdvance.set(-prefix.length() - 1); } return Result.Default; }