PY-27860 RST icon blinking in "Structure" panel

This commit is contained in:
Ekaterina Tuzova
2018-06-07 19:55:54 +03:00
parent 87cd19118b
commit 3f68aec01d
7 changed files with 123 additions and 68 deletions

View File

@@ -20,12 +20,14 @@ import com.intellij.ide.structureView.impl.common.PsiTreeElementBase;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.NavigatablePsiElement;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import com.jetbrains.rest.psi.RestTitle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
@@ -71,7 +73,7 @@ public class RestStructureViewElement extends PsiTreeElementBase<NavigatablePsiE
break;
}
if (underline.equals(adornmentsToUse.getSecond()) && ((adornmentsToUse.getFirst() == null && overline == null) ||
adornmentsToUse.getFirst().equals(overline))) {
(overline != null && overline.equals(adornmentsToUse.getFirst())))) {
result.add(new RestStructureViewElement(child));
}
}
@@ -97,4 +99,13 @@ public class RestStructureViewElement extends PsiTreeElementBase<NavigatablePsiE
final NavigatablePsiElement element = getElement();
return element != null ? element.getName() : "";
}
@Override
public Icon getIcon(boolean open) {
final PsiElement element = getElement();
if (!(element instanceof PsiFile)) {
return null;
}
return super.getIcon(open);
}
}

View File

@@ -0,0 +1,5 @@
Chapter 1 Title
===============
Chapter 2 Title
===============

View File

@@ -0,0 +1,14 @@
Chapter 1 Title
===============
Section 1.1 Title
-----------------
Subsection 1.1.1 Title
~~~~~~~~~~~~~~~~~~~~~~
Section 1.2 Title
-----------------
Chapter 2 Title
===============

View File

@@ -0,0 +1,6 @@
Chapter 1 Title
===============
Chapter 2 Title
===============

View File

@@ -0,0 +1,30 @@
The following document:
============
Hello, world
============
A section
=========
A subsection
------------
A sub-subsection
````````````````
An other one
````````````
Back up
=======
And down
--------
twice
-----
with feelings
`````````````

View File

@@ -0,0 +1,56 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.rest
import com.intellij.testFramework.PlatformTestUtil
import com.intellij.testFramework.PlatformTestUtil.assertTreeEqual
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase
class RestStructureViewTest : LightPlatformCodeInsightFixtureTestCase() {
fun `test plain structure`() {
doTest("-plain structure.rst\n" +
" Chapter 1 Title\n" +
" Chapter 2 Title\n")
}
fun `test file beginning`() {
doTest("-file beginning.rst\n" +
" Chapter 1 Title\n" +
" Chapter 2 Title\n")
}
fun `test one inner section`() {
doTest("-one inner section.rst\n" +
" -Chapter 1 Title\n" +
" -Section 1.1 Title\n" +
" Subsection 1.1.1 Title\n" +
" Section 1.2 Title\n" +
" Chapter 2 Title\n")
}
fun `test tree`() {
doTest("-tree.rst\n" +
" -Hello, world\n" +
" -A section\n" +
" -A subsection\n" +
" A sub-subsection\n" +
" An other one\n" +
" -Back up\n" +
" And down\n" +
" -twice\n" +
" with feelings\n")
}
private fun doTest(expected: String) {
myFixture.configureByFile("/structureView/" + getTestName(true).trim() + ".rst")
myFixture.testStructureView { svc ->
PlatformTestUtil.expandAll(svc.tree)
assertTreeEqual(svc.tree, expected)
}
}
override fun getBasePath(): String {
return "python/rest/testData"
}
override fun isCommunity(): Boolean = true
}