IDEA-180497 Parameter name hints: incorrect behavior in case of varargs

fix caret position after completion between hints
This commit is contained in:
Dmitry Batrak
2017-10-13 11:53:53 +03:00
parent 250956f8b0
commit 7384bdc1a5
3 changed files with 23 additions and 31 deletions
@@ -715,6 +715,15 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
checkHintContents("<html><b>Class&lt;?&gt;</b></html>");
}
public void testCompletionBetweenVarargHints() {
configureJava("class C { int myVal = 1; void vararg(int a, int... b) {} void m() { varar<caret> } }");
complete();
checkResultWithInlays("class C { int myVal = 1; void vararg(int a, int... b) {} void m() { vararg(<HINT text=\"a:\"/><caret><hint text=\", b:\"/>); } }");
type("myVa");
complete();
checkResultWithInlays("class C { int myVal = 1; void vararg(int a, int... b) {} void m() { vararg(<HINT text=\"a:\"/>myVal<caret><hint text=\", b:\"/>); } }");
}
private void checkResult(String text) {
myFixture.checkResult(text);
}
@@ -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) {
@@ -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("<caret>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);