mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-65126 Move method and folding bug
This is a complement to the commit 83995c6a77. The test is added
This commit is contained in:
@@ -20,6 +20,8 @@ import com.intellij.codeInsight.folding.impl.CodeFoldingManagerImpl
|
||||
import com.intellij.codeInsight.folding.impl.JavaCodeFoldingSettingsImpl
|
||||
import com.intellij.find.FindManager
|
||||
import com.intellij.openapi.application.ex.PathManagerEx
|
||||
import com.intellij.openapi.editor.FoldRegion
|
||||
import com.intellij.openapi.editor.ex.FoldingModelEx
|
||||
import com.intellij.openapi.editor.impl.FoldingModelImpl
|
||||
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
@@ -215,9 +217,56 @@ class Test {
|
||||
myFixture.testFolding("$PathManagerEx.testDataPath/codeInsight/folding/${getTestName(false)}.java");
|
||||
}
|
||||
|
||||
public void "test move methods"() {
|
||||
def initialText = '''\
|
||||
class Test {
|
||||
void test1() {
|
||||
}
|
||||
|
||||
void test2() {
|
||||
}
|
||||
}
|
||||
'''
|
||||
|
||||
Closure<FoldRegion> fold = { String methodName ->
|
||||
def text = myFixture.editor.document.text
|
||||
def nameIndex = text.indexOf(methodName)
|
||||
def start = text.indexOf('{', nameIndex)
|
||||
def end = text.indexOf('}', start) + 1
|
||||
def regions = myFixture.editor.foldingModel.allFoldRegions
|
||||
for (region in regions) {
|
||||
if (region.startOffset == start && region.endOffset == end) {
|
||||
return region
|
||||
}
|
||||
}
|
||||
fail("Can't find target fold region for method with name '$methodName'. Registered regions: $regions")
|
||||
null
|
||||
}
|
||||
|
||||
configure initialText
|
||||
def foldingModel = myFixture.editor.foldingModel as FoldingModelEx
|
||||
foldingModel.runBatchFoldingOperation {
|
||||
fold('test1').expanded = true
|
||||
fold('test2').expanded = false
|
||||
}
|
||||
|
||||
myFixture.editor.caretModel.moveToOffset(initialText.indexOf('void'))
|
||||
myFixture.performEditorAction 'MoveStatementDown'
|
||||
CodeFoldingManager.getInstance(project).updateFoldRegions(myFixture.editor)
|
||||
assertTrue(fold('test1').expanded)
|
||||
assertFalse(fold('test2').expanded)
|
||||
|
||||
myFixture.performEditorAction 'MoveStatementUp'
|
||||
CodeFoldingManager.getInstance(project).updateFoldRegions(myFixture.editor)
|
||||
assertTrue(fold('test1').expanded)
|
||||
assertFalse(fold('test2').expanded)
|
||||
}
|
||||
|
||||
private def configure(String text) {
|
||||
myFixture.configureByText("a.java", text)
|
||||
CodeFoldingManagerImpl.getInstance(getProject()).buildInitialFoldings(myFixture.editor);
|
||||
def foldingModel = myFixture.editor.foldingModel as FoldingModelEx
|
||||
foldingModel.rebuild()
|
||||
myFixture.doHighlighting()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user