From 4a494f9bf1c411ed6540d6dc9d7401ce8a1e3aeb Mon Sep 17 00:00:00 2001 From: jojo2357 <66704796+jojo2357@users.noreply.github.com> Date: Mon, 5 Feb 2024 16:21:44 -0700 Subject: [PATCH 1/3] Fold Equations --- .../editor/folding/LatexMathSymbolFoldingBuilder.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/nl/hannahsten/texifyidea/editor/folding/LatexMathSymbolFoldingBuilder.kt b/src/nl/hannahsten/texifyidea/editor/folding/LatexMathSymbolFoldingBuilder.kt index e1ecb3e01..7c976c630 100644 --- a/src/nl/hannahsten/texifyidea/editor/folding/LatexMathSymbolFoldingBuilder.kt +++ b/src/nl/hannahsten/texifyidea/editor/folding/LatexMathSymbolFoldingBuilder.kt @@ -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 @@ -20,8 +22,9 @@ class LatexMathSymbolFoldingBuilder : FoldingBuilderEx(), DumbAware { override fun buildFoldRegions(root: PsiElement, document: Document, quick: Boolean): Array { val descriptors = listOf().toMutableList() val mathEnvironments = root.childrenOfType(LatexMathEnvironment::class) + val mathThings = root.childrenOfType(LatexEnvironmentContent::class).filter{ it.inMathContext() } - for (mathEnvironment in mathEnvironments) { + for (mathEnvironment in arrayOf(mathEnvironments, mathThings).toList().flatten()) { val group = FoldingGroup.newGroup("latexMathSymbol") val commands = mathEnvironment.childrenOfType(LatexCommands::class) From cb2debaa5d387079ec6808a737c7c2325b6438e4 Mon Sep 17 00:00:00 2001 From: jojo2357 <66704796+jojo2357@users.noreply.github.com> Date: Mon, 5 Feb 2024 16:45:26 -0700 Subject: [PATCH 2/3] Add Test --- test/nl/hannahsten/texifyidea/editor/LatexFoldingTest.kt | 7 +++++++ test/resources/editor/folding/math-symbols-environment.tex | 3 +++ 2 files changed, 10 insertions(+) create mode 100644 test/resources/editor/folding/math-symbols-environment.tex diff --git a/test/nl/hannahsten/texifyidea/editor/LatexFoldingTest.kt b/test/nl/hannahsten/texifyidea/editor/LatexFoldingTest.kt index 0cfbb8358..60a1c76f0 100644 --- a/test/nl/hannahsten/texifyidea/editor/LatexFoldingTest.kt +++ b/test/nl/hannahsten/texifyidea/editor/LatexFoldingTest.kt @@ -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") } diff --git a/test/resources/editor/folding/math-symbols-environment.tex b/test/resources/editor/folding/math-symbols-environment.tex new file mode 100644 index 000000000..32916bc05 --- /dev/null +++ b/test/resources/editor/folding/math-symbols-environment.tex @@ -0,0 +1,3 @@ +\begin{equation} + \xi^\alpha +\end{equation} \ No newline at end of file From 35cb8ab6b72a3fab71d6d738e678ae1d2be4defb Mon Sep 17 00:00:00 2001 From: Thomas Schouten Date: Tue, 6 Feb 2024 21:21:00 +0100 Subject: [PATCH 3/3] Rename variables and replace array-list-flatten by list concatenation --- .../editor/folding/LatexMathSymbolFoldingBuilder.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nl/hannahsten/texifyidea/editor/folding/LatexMathSymbolFoldingBuilder.kt b/src/nl/hannahsten/texifyidea/editor/folding/LatexMathSymbolFoldingBuilder.kt index 8530fd986..3ca27ca5f 100644 --- a/src/nl/hannahsten/texifyidea/editor/folding/LatexMathSymbolFoldingBuilder.kt +++ b/src/nl/hannahsten/texifyidea/editor/folding/LatexMathSymbolFoldingBuilder.kt @@ -21,10 +21,10 @@ class LatexMathSymbolFoldingBuilder : FoldingBuilderEx(), DumbAware { override fun buildFoldRegions(root: PsiElement, document: Document, quick: Boolean): Array { val descriptors = listOf().toMutableList() - val mathEnvironments = root.childrenOfType(LatexMathEnvironment::class) - val mathThings = root.childrenOfType(LatexEnvironmentContent::class).filter{ it.inMathContext() } + val inlineOrDisplayMath = root.childrenOfType(LatexMathEnvironment::class) + val mathEnvironments = root.childrenOfType(LatexEnvironmentContent::class).filter { it.inMathContext() } - for (mathEnvironment in arrayOf(mathEnvironments, mathThings).toList().flatten()) { + for (mathEnvironment in inlineOrDisplayMath + mathEnvironments) { val group = FoldingGroup.newGroup("latexMathSymbol") val commands = mathEnvironment.childrenOfType(LatexCommands::class)