mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-17 21:43:33 +07:00
ensure caret position invariant during inplace rename
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
*/
|
||||
package com.intellij.refactoring
|
||||
|
||||
import com.intellij.codeInsight.TargetElementUtilBase
|
||||
import com.intellij.codeInsight.template.TemplateManager
|
||||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl
|
||||
import com.intellij.codeInsight.template.impl.TemplateState
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
*/
|
||||
class InplaceRenameInvariantTest extends LightCodeInsightTestCase {
|
||||
public void "test start caret position"() {
|
||||
def text = """\
|
||||
class <caret>Test {
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
doTestPositionInvariance(text, false)
|
||||
}
|
||||
|
||||
public void "test middle caret position"() {
|
||||
def text = """\
|
||||
class Te<caret>st {
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
doTestPositionInvariance(text, false)
|
||||
}
|
||||
|
||||
public void "test end caret position"() {
|
||||
def text = """\
|
||||
class Test<caret> {
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
doTestPositionInvariance(text, false)
|
||||
}
|
||||
|
||||
|
||||
public void "test start caret position preselect"() {
|
||||
def text = """\
|
||||
class <caret>Test {
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
doTestPositionInvariance(text, true)
|
||||
}
|
||||
|
||||
public void "test middle caret position preselect"() {
|
||||
def text = """\
|
||||
class Te<caret>st {
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
doTestPositionInvariance(text, true)
|
||||
}
|
||||
|
||||
public void "test end caret position preselect"() {
|
||||
def text = """\
|
||||
class Test<caret> {
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
doTestPositionInvariance(text, true)
|
||||
}
|
||||
|
||||
private doTestPositionInvariance(String text, final boolean preselect) {
|
||||
configure text
|
||||
TemplateManagerImpl templateManager = (TemplateManagerImpl)TemplateManager.getInstance(project)
|
||||
def oldPreselectSetting = myEditor.settings.preselectRename
|
||||
try {
|
||||
templateManager.templateTesting = true
|
||||
myEditor.settings.preselectRename = preselect;
|
||||
int offset = myEditor.caretModel.offset
|
||||
final PsiElement element = TargetElementUtilBase.findTargetElement(myEditor, TargetElementUtilBase.getInstance().getAllAccepted())
|
||||
|
||||
assertNotNull(element)
|
||||
|
||||
MemberInplaceRenameHandler handler = new MemberInplaceRenameHandler()
|
||||
|
||||
|
||||
handler.doRename(element, editor, null);
|
||||
|
||||
assertEquals(offset, myEditor.caretModel.offset)
|
||||
}
|
||||
finally {
|
||||
myEditor.settings.preselectRename = oldPreselectSetting
|
||||
|
||||
try {
|
||||
TemplateState state = TemplateManagerImpl.getTemplateState(editor)
|
||||
|
||||
assertNotNull(state)
|
||||
|
||||
state.gotoEnd(false)
|
||||
}
|
||||
finally {
|
||||
templateManager.templateTesting = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private def configure(String text) {
|
||||
configureFromFileText("a.java", text)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user