mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 20:39:40 +07:00
IDEA-173273 Renaming a parameter with a hint looks weird
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
class C {
|
||||
private static final int VALUE = 2;
|
||||
|
||||
void m(int a, int b) {}
|
||||
|
||||
void m2() {
|
||||
m(1, <caret>VALUE);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -17,11 +17,9 @@ package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.TargetElementUtil;
|
||||
import com.intellij.codeInsight.template.TemplateManager;
|
||||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
|
||||
import com.intellij.codeInsight.template.impl.TemplateState;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.injected.editor.EditorWindow;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -29,6 +27,7 @@ import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.refactoring.rename.JavaNameSuggestionProvider;
|
||||
import com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler;
|
||||
import com.intellij.testFramework.EditorTestUtil;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -149,6 +148,22 @@ public class RenameMembersInplaceTest extends LightCodeInsightTestCase {
|
||||
fail("Conflict was not detected");
|
||||
}
|
||||
|
||||
public void testNearParameterHint() throws Exception {
|
||||
configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
|
||||
int originalCaretPosition = myEditor.getCaretModel().getOffset();
|
||||
EditorTestUtil.addInlay(myEditor, originalCaretPosition);
|
||||
// make sure caret is to the right of inlay initially
|
||||
myEditor.getCaretModel().moveToLogicalPosition(myEditor.getCaretModel().getLogicalPosition().leanForward(true));
|
||||
|
||||
final PsiElement element = TargetElementUtil.findTargetElement(myEditor, TargetElementUtil.getInstance().getAllAccepted());
|
||||
assertNotNull(element);
|
||||
|
||||
TemplateManagerImpl.setTemplateTesting(ourProject, getTestRootDisposable());
|
||||
new MemberInplaceRenameHandler().doRename(element, myEditor, DataManager.getInstance().getDataContext(myEditor.getComponent()));
|
||||
assertEquals(originalCaretPosition, myEditor.getCaretModel().getOffset());
|
||||
assertTrue(myEditor.getCaretModel().getLogicalPosition().leansForward); // check caret is still to the right
|
||||
}
|
||||
|
||||
private void doTestInplaceRename(final String newName) throws Exception {
|
||||
configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
|
||||
|
||||
|
||||
@@ -587,7 +587,7 @@ public class TemplateState implements Disposable {
|
||||
final int start = mySegments.getSegmentStart(currentSegmentNumber);
|
||||
final int end = mySegments.getSegmentEnd(currentSegmentNumber);
|
||||
if (end >= 0) {
|
||||
myEditor.getCaretModel().moveToOffset(end);
|
||||
myEditor.getCaretModel().moveToLogicalPosition(myEditor.offsetToLogicalPosition(end).leanForward(true)); // to the right of parameter hint, if any
|
||||
myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
|
||||
myEditor.getSelectionModel().removeSelection();
|
||||
myEditor.getSelectionModel().setSelection(start, end);
|
||||
|
||||
@@ -391,7 +391,8 @@ public abstract class InplaceRefactoring {
|
||||
template.setToShortenLongNames(false);
|
||||
template.setToReformat(false);
|
||||
myHighlighters = new ArrayList<>();
|
||||
topLevelEditor.getCaretModel().moveToOffset(rangeMarker.getStartOffset());
|
||||
int targetOffset = rangeMarker.getStartOffset();
|
||||
topLevelEditor.getCaretModel().moveToLogicalPosition(topLevelEditor.offsetToLogicalPosition(targetOffset).leanForward(true)); // to the right of parameter hint, if any
|
||||
|
||||
TemplateManager.getInstance(myProject).startTemplate(topLevelEditor, template, templateListener);
|
||||
restoreOldCaretPositionAndSelection(offset);
|
||||
@@ -426,7 +427,8 @@ public abstract class InplaceRefactoring {
|
||||
private void restoreOldCaretPositionAndSelection(final int offset) {
|
||||
//move to old offset
|
||||
Runnable runnable = () -> {
|
||||
myEditor.getCaretModel().moveToOffset(restoreCaretOffset(offset));
|
||||
int targetOffset = restoreCaretOffset(offset);
|
||||
myEditor.getCaretModel().moveToLogicalPosition(myEditor.offsetToLogicalPosition(targetOffset).leanForward(true)); // to the right of parameter hint, if any
|
||||
restoreSelection();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user