Skip to content

Commit

Permalink
Fix nullpointer
Browse files Browse the repository at this point in the history
  • Loading branch information
PHPirates committed Dec 19, 2024
1 parent df8df07 commit cd88255
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

### Added
* Add sections to breadcrumbs
* Change order in structure view to match source file and sectioning level
* Add command redefinitions to command definition filter in structure view
* Add support for automatic language injection on the minted environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import nl.hannahsten.texifyidea.grammar.LatexLanguage
import nl.hannahsten.texifyidea.psi.LatexCommands
import nl.hannahsten.texifyidea.psi.LatexEnvironment
import nl.hannahsten.texifyidea.util.files.document
import nl.hannahsten.texifyidea.util.magic.CommandMagic
import nl.hannahsten.texifyidea.util.magic.cmd
import nl.hannahsten.texifyidea.util.parser.name
import nl.hannahsten.texifyidea.util.parser.parents
import nl.hannahsten.texifyidea.util.parser.requiredParameter
Expand All @@ -20,7 +22,7 @@ open class LatexBreadcrumbsInfo : BreadcrumbsProvider {

override fun getElementInfo(element: PsiElement) = when (element) {
is LatexEnvironment -> element.name()?.text
is LatexCommands -> if (element.name == "\\section") element.requiredParameter(0) else element.name
is LatexCommands -> if (element.name in CommandMagic.sectioningCommands.map { it.cmd }) element.requiredParameter(0) ?: element.name else element.name
else -> ""
} ?: ""

Expand All @@ -32,10 +34,11 @@ open class LatexBreadcrumbsInfo : BreadcrumbsProvider {

override fun getParent(element: PsiElement): PsiElement? {
val document = element.containingFile.document() ?: return super.getParent(element)
// Add sections
val parent = LatexSectionFoldingBuilder().buildFoldRegions(element.containingFile, document, quick = true)
// Only top-level elements in the section should have the section as parents, other elements should keep their direct parent (e.g. an environment)
.filter { it.range.contains(element.textRange) }
.filterNot { it.range.contains(element.parent.textRange) }
.filter { it.range.contains(element.textRange ?: return@filter false) }
.filterNot { it.range.contains(element.parent.textRange ?: return@filterNot true) }
.firstOrNull { it.element.psi != element }
?.element?.psi
// Avoid creating a loop
Expand Down

0 comments on commit cd88255

Please sign in to comment.