diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionHintsTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionHintsTest.java
index ad03f90aa65f..8953f51a4f6c 100644
--- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionHintsTest.java
+++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionHintsTest.java
@@ -715,6 +715,15 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
checkHintContents("Class<?>");
}
+ public void testCompletionBetweenVarargHints() {
+ configureJava("class C { int myVal = 1; void vararg(int a, int... b) {} void m() { varar } }");
+ complete();
+ checkResultWithInlays("class C { int myVal = 1; void vararg(int a, int... b) {} void m() { vararg(); } }");
+ type("myVa");
+ complete();
+ checkResultWithInlays("class C { int myVal = 1; void vararg(int a, int... b) {} void m() { vararg(myVal); } }");
+ }
+
private void checkResult(String text) {
myFixture.checkResult(text);
}
diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretImpl.java
index fee2cdb6f081..dc99ce4b231d 100644
--- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretImpl.java
+++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/CaretImpl.java
@@ -1,18 +1,4 @@
-/*
- * Copyright 2000-2017 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.editor.impl;
import com.intellij.diagnostic.Dumpable;
@@ -1562,7 +1548,7 @@ public class CaretImpl extends UserDataHolderBase implements Caret, Dumpable {
setIntervalStart(newOffset);
setIntervalEnd(newOffset);
}
- if (oldOffset >= e.getOffset() && oldOffset <= e.getOffset() + e.getOldLength() && e.getNewLength() == 0) {
+ if (oldOffset >= e.getOffset() && oldOffset <= e.getOffset() + e.getOldLength() && e.getNewLength() == 0 && e.getOldLength() > 0) {
int inlaysToTheLeft = myEditor.getInlayModel().getInlineElementsInRange(e.getOffset(), e.getOffset()).size();
boolean hasInlaysToTheRight = myEditor.getInlayModel().hasInlineElementAt(e.getOffset() + e.getOldLength());
if (inlaysToTheLeft > 0 || hasInlaysToTheRight) {
diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorInlayTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorInlayTest.java
index 446123746972..d6bfea5ef269 100644
--- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorInlayTest.java
+++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorInlayTest.java
@@ -1,18 +1,4 @@
-/*
- * Copyright 2000-2017 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.editor.impl;
import com.intellij.openapi.command.WriteCommandAction;
@@ -327,6 +313,17 @@ public class EditorInlayTest extends AbstractEditorTest {
assertTrue(i2.isValid() && i2.getOffset() == 4);
}
+ public void testNoOpReplaceDoesntMoveCaret() {
+ initText("abc");
+ addInlay(2);
+ right();
+ right();
+ WriteCommandAction.runWriteCommandAction(ourProject, () -> {
+ myEditor.getDocument().replaceString(1, 2, "b");
+ });
+ checkCaretPosition(2, 2, 2);
+ }
+
private static void checkCaretPositionAndSelection(int offset, int logicalColumn, int visualColumn,
int selectionStartOffset, int selectionEndOffset) {
checkCaretPosition(offset, logicalColumn, visualColumn);