mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Live Templates: bulk update should change later segment first (IDEA-167694)
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user