Skip to content

Commit

Permalink
Merge pull request #3445 from jojo2357/equation-folding
Browse files Browse the repository at this point in the history
Fold Equations
  • Loading branch information
PHPirates authored Feb 6, 2024
2 parents 2eb6d85 + 35cb8ab commit 029edc8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import com.intellij.openapi.project.DumbAware
import com.intellij.psi.PsiElement
import nl.hannahsten.texifyidea.lang.commands.LatexMathCommand
import nl.hannahsten.texifyidea.psi.LatexCommands
import nl.hannahsten.texifyidea.psi.LatexEnvironmentContent
import nl.hannahsten.texifyidea.psi.LatexMathEnvironment
import nl.hannahsten.texifyidea.util.parser.childrenOfType
import nl.hannahsten.texifyidea.util.parser.inMathContext

/**
* @author Sten Wessel
Expand All @@ -19,9 +21,10 @@ class LatexMathSymbolFoldingBuilder : FoldingBuilderEx(), DumbAware {

override fun buildFoldRegions(root: PsiElement, document: Document, quick: Boolean): Array<FoldingDescriptor> {
val descriptors = listOf<FoldingDescriptor>().toMutableList()
val mathEnvironments = root.childrenOfType(LatexMathEnvironment::class)
val inlineOrDisplayMath = root.childrenOfType(LatexMathEnvironment::class)
val mathEnvironments = root.childrenOfType(LatexEnvironmentContent::class).filter { it.inMathContext() }

for (mathEnvironment in mathEnvironments) {
for (mathEnvironment in inlineOrDisplayMath + mathEnvironments) {
val group = FoldingGroup.newGroup("latexMathSymbol")
val commands = mathEnvironment.childrenOfType(LatexCommands::class)

Expand Down
7 changes: 7 additions & 0 deletions test/nl/hannahsten/texifyidea/editor/LatexFoldingTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class LatexFoldingTest : BasePlatformTestCase() {
}
}

fun testMathSymbolFoldingInEnvironment() {
// Unicode issues on windows
if (!SystemInfo.isWindows) {
myFixture.testFolding("$testDataPath/math-symbols-environment.tex")
}
}

fun testSectionFolding() {
myFixture.testFolding("$testDataPath/sections.tex")
}
Expand Down
3 changes: 3 additions & 0 deletions test/resources/editor/folding/math-symbols-environment.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\begin{equation}<fold text='...'>
<fold text='ξ'>\xi</fold>^<fold text='α'>\alpha</fold>
</fold>\end{equation}

0 comments on commit 029edc8

Please sign in to comment.