Live Templates: bulk update should change later segment first (IDEA-167694)

This commit is contained in:
Alexander Zolotov
2017-02-07 15:17:23 +03:00
parent f69cc32911
commit bebc20f086
2 changed files with 14 additions and 4 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 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.
@@ -113,6 +113,16 @@ class LiveTemplateTest extends LightCodeInsightFixtureTestCase {
doTestTemplateWithThreeVariables("", "DefaultValue", "", "class A { void test() { for(TestValue1DefaultValueTestValue3) {} } }")
}
void testTemplateWithSegmentsAtTheSamePosition_4() {
configureFromFileText("dummy.java", "class A { void test() { <caret> } }")
TemplateManager manager = TemplateManager.getInstance(getProject())
final Template template = manager.createTemplate("test_template", "user_group", '$A$$B$ then "$A$$B$"')
template.addVariable("A", "", "\"Def1\"", true)
template.addVariable("B", "", "\"Def2\"", true)
startTemplate(template)
checkResultByText("class A { void test() { Def1Def2 then \"Def1Def2\" } }")
}
private void doTestTemplateWithThreeVariables(String firstDefaultValue, String secondDefaultValue, String thirdDefaultValue, String expectedText) {
configureFromFileText("dummy.java", "class A { void test() { <caret> } }")
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 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.
@@ -786,7 +786,7 @@ public class TemplateState implements Disposable {
if (changes.size() > 1) {
ContainerUtil.sort(changes, (o1, o2) -> {
int startDiff = o2.startOffset - o1.startOffset;
return startDiff != 0 ? startDiff : o2.endOffset - o1.endOffset;
return startDiff != 0 ? startDiff : o2.segmentNumber - o1.segmentNumber;
});
}
DocumentUtil.executeInBulk(myDocument, true, () -> {
@@ -797,7 +797,7 @@ public class TemplateState implements Disposable {
}
/**
* Must be invoked on every segment change in order to avoid ovelapping editing segment with its neibours
* Must be invoked on every segment change in order to avoid overlapping editing segment with its neighbours
*/
private void fixOverlappedSegments(int currentSegment) {
if (currentSegment >= 0) {