From 08d0e2cfafc061ea7f57311a4c25b2adc7cf6d3d Mon Sep 17 00:00:00 2001 From: Abby Berkers Date: Wed, 11 Oct 2023 21:32:03 +0200 Subject: [PATCH 1/2] Add structure view elements to correct level (fixes #3273) --- .../texifyidea/structure/latex/LatexStructureViewElement.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewElement.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewElement.kt index ae528ccdc..f60a5a4a8 100644 --- a/src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewElement.kt +++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewElement.kt @@ -195,7 +195,7 @@ class LatexStructureViewElement(private val element: PsiElement) : StructureView } // Avoid that an element is not added at all by adding it one level up anyway. // If index is null, that means that the tree currently only has elements with a higher order. - else { + else if (index == null || indexInsert == index) { registerSameLevel(sections, child, currentCmd, treeElements, numbering) break } From 14ea7d31ffcfa7b21f471fceb7674b6cb58d8557 Mon Sep 17 00:00:00 2001 From: Abby Berkers Date: Wed, 11 Oct 2023 22:08:23 +0200 Subject: [PATCH 2/2] Added test --- .../latex/LatexStructureViewElementTest.kt | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 test/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewElementTest.kt diff --git a/test/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewElementTest.kt b/test/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewElementTest.kt new file mode 100644 index 000000000..7a99c64b2 --- /dev/null +++ b/test/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewElementTest.kt @@ -0,0 +1,60 @@ +package nl.hannahsten.texifyidea.structure.latex + +import com.intellij.testFramework.fixtures.BasePlatformTestCase +import nl.hannahsten.texifyidea.file.LatexFileType + +class LatexStructureViewElementTest : BasePlatformTestCase() { + fun `test that item is added to correct level when it is more than one level higher than the previous element`() { + myFixture.configureByText( + LatexFileType, + """ + \section{s} + + \subsection{ss1} + + \subsubsection{sss} + + \paragraph{p} + + \subsection{ss2} + """.trimIndent() + ) + + myFixture.testStructureView { component -> + val documentChildren = (component.treeModel as LatexStructureViewModel).root.children + // \section{s1} is the only child element of the document class element. + assertEquals(1, documentChildren.size) + // \subsection{ss1} + // ... + // \subsection{ss2} + assertEquals( + listOf("\\subsection{ss1}", "\\subsection{ss2}"), + documentChildren[0].children.map { (it as LatexStructureViewCommandElement).value.text } + ) + } + } + + fun `test that item is added to tree when all items before where of lower level`() { + myFixture.configureByText( + LatexFileType, + """ + \subsubsection{sss} + + \paragraph{p} + + \subsection{ss} + """.trimIndent() + ) + + myFixture.testStructureView { component -> + val documentChildren = (component.treeModel as LatexStructureViewModel).root.children + // \subsubsection{sss} + // \paragraph{p} + // \subsection{ss} + assertEquals( + listOf("\\subsubsection{sss}", "\\subsection{ss}"), + documentChildren.map { (it as LatexStructureViewCommandElement).value.text } + ) + } + } +} \ No newline at end of file