Skip to content

Commit

Permalink
Merge pull request #3278 from Hannah-Sten/3273-structure-view
Browse files Browse the repository at this point in the history
3273 Fix structure view nesting
  • Loading branch information
PHPirates authored Oct 14, 2023
2 parents c0386f7 + 14ea7d3 commit 625acea
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 }
)
}
}
}

0 comments on commit 625acea

Please sign in to comment.