mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
inplace rename: preserve caret at the place it was left by user
This commit is contained in:
@@ -34,7 +34,7 @@ class InplaceRenameInvariantTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
"""
|
||||
|
||||
doTestPositionInvariance(text, false)
|
||||
doTestPositionInvariance(text, false, false)
|
||||
}
|
||||
|
||||
public void "test middle caret position"() {
|
||||
@@ -44,7 +44,7 @@ class InplaceRenameInvariantTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
"""
|
||||
|
||||
doTestPositionInvariance(text, false)
|
||||
doTestPositionInvariance(text, false, false)
|
||||
}
|
||||
|
||||
public void "test end caret position"() {
|
||||
@@ -54,7 +54,18 @@ class InplaceRenameInvariantTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
"""
|
||||
|
||||
doTestPositionInvariance(text, false)
|
||||
doTestPositionInvariance(text, false, false)
|
||||
}
|
||||
|
||||
public void "test end caret position typing"() {
|
||||
def text = """\
|
||||
class Test {
|
||||
Test<caret> myTest;
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
doTestPositionInvariance(text, false, false)
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +76,7 @@ class InplaceRenameInvariantTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
"""
|
||||
|
||||
doTestPositionInvariance(text, true)
|
||||
doTestPositionInvariance(text, true, false)
|
||||
}
|
||||
|
||||
public void "test middle caret position preselect"() {
|
||||
@@ -75,7 +86,7 @@ class InplaceRenameInvariantTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
"""
|
||||
|
||||
doTestPositionInvariance(text, true)
|
||||
doTestPositionInvariance(text, true, false)
|
||||
}
|
||||
|
||||
public void "test end caret position preselect"() {
|
||||
@@ -85,10 +96,10 @@ class InplaceRenameInvariantTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
"""
|
||||
|
||||
doTestPositionInvariance(text, true)
|
||||
doTestPositionInvariance(text, true, false)
|
||||
}
|
||||
|
||||
private doTestPositionInvariance(String text, final boolean preselect) {
|
||||
private doTestPositionInvariance(String text, final boolean preselect, final boolean checkTyping) {
|
||||
configure text
|
||||
TemplateManagerImpl templateManager = (TemplateManagerImpl)TemplateManager.getInstance(project)
|
||||
def oldPreselectSetting = myEditor.settings.preselectRename
|
||||
@@ -104,6 +115,11 @@ class InplaceRenameInvariantTest extends LightCodeInsightTestCase {
|
||||
|
||||
|
||||
handler.doRename(element, editor, null);
|
||||
|
||||
if (checkTyping){
|
||||
type '1'
|
||||
offset++
|
||||
}
|
||||
|
||||
assertEquals(offset, myEditor.caretModel.offset)
|
||||
}
|
||||
|
||||
+6
-2
@@ -716,10 +716,14 @@ public abstract class InplaceRefactoring {
|
||||
final TextResult value = templateState.getVariableValue(PRIMARY_VARIABLE_NAME);
|
||||
myInsertedName = value != null ? value.toString() : null;
|
||||
|
||||
TextRange range = templateState.getCurrentVariableRange();
|
||||
final int currentOffset = myEditor.getCaretModel().getOffset();
|
||||
if (range == null && myRenameOffset != null) {
|
||||
range = new TextRange(myRenameOffset.getStartOffset(), myRenameOffset.getEndOffset());
|
||||
}
|
||||
myBeforeRevert =
|
||||
myRenameOffset != null && myRenameOffset.getEndOffset() >= currentOffset && myRenameOffset.getStartOffset() <= currentOffset
|
||||
? myEditor.getDocument().createRangeMarker(myRenameOffset.getStartOffset(), currentOffset)
|
||||
range != null && range.getEndOffset() >= currentOffset && range.getStartOffset() <= currentOffset
|
||||
? myEditor.getDocument().createRangeMarker(range.getStartOffset(), currentOffset)
|
||||
: null;
|
||||
if (myBeforeRevert != null) {
|
||||
myBeforeRevert.setGreedyToRight(true);
|
||||
|
||||
Reference in New Issue
Block a user