Skip to content

Commit

Permalink
Fix math context and second part of #3700
Browse files Browse the repository at this point in the history
  • Loading branch information
PHPirates committed Dec 6, 2024
1 parent 3b74e7e commit 5b88bba
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ dependencies {
plugin("com.firsttimeinforever.intellij.pdf.viewer.intellij-pdf-viewer:0.17.0")
plugin("com.jetbrains.hackathon.indices.viewer:1.28")
// Does not work in tests: https://youtrack.jetbrains.com/issue/GRZ-5023
plugin("com.intellij.grazie.pro:0.3.347")
// plugin("com.intellij.grazie.pro:0.3.347")
}

// Local dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import nl.hannahsten.texifyidea.lang.commands.LatexCommand
import nl.hannahsten.texifyidea.psi.*
import nl.hannahsten.texifyidea.util.merge
import nl.hannahsten.texifyidea.util.overlaps
import nl.hannahsten.texifyidea.util.parser.childrenOfType
import nl.hannahsten.texifyidea.util.parser.endOffset
import nl.hannahsten.texifyidea.util.parser.firstParentOfType
import nl.hannahsten.texifyidea.util.parser.parents
import nl.hannahsten.texifyidea.util.parser.*
import nl.hannahsten.texifyidea.util.toTextRange

/**
Expand Down Expand Up @@ -53,7 +50,7 @@ class LatexTextExtractor : TextExtractor() {
// Only keep normaltext, assuming other things (like inline math) need to be ignored.
val ranges = (root.childrenOfType(LatexNormalText::class) + root.childrenOfType<LatexParameterText>() + root.childrenOfType<PsiWhiteSpace>())
.asSequence()
.filter { it.isNotInMathEnvironment() && it.isNotInSquareBrackets() }
.filter { !it.inMathContext() && it.isNotInSquareBrackets() }
// Ranges that we need to keep
// Note that textRangeInParent will not be correct because that's the text range in the direct parent, not in the root
.flatMap { text ->
Expand Down Expand Up @@ -118,8 +115,6 @@ class LatexTextExtractor : TextExtractor() {
return ranges.sortedBy { it.first }
}

private fun PsiElement.isNotInMathEnvironment() = parents().none { it is LatexMathEnvironment }

private fun PsiElement.isNotInSquareBrackets() = parents().find { it is LatexGroup || it is LatexOptionalParam }
?.let { it is LatexGroup } ?: true
}

0 comments on commit 5b88bba

Please sign in to comment.