From cafc3a89efd9a448610dba264dbd43ea8542b428 Mon Sep 17 00:00:00 2001 From: Thomas Schouten Date: Tue, 19 Nov 2024 20:59:39 +0100 Subject: [PATCH] Check for invalid psi elements in firstParentOfType, fix #3326 --- CHANGELOG.md | 1 + src/nl/hannahsten/texifyidea/util/parser/Psi.kt | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 167951aa5..3a5a13e73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Don't insert the right brace when in front of text ### Fixed +* Fix exceptions #3754 and #3326 * Fix exceptions in structure view when command parameters are missing * Improve error report submitter for long stacktraces * Fix a parser issue with bidirectional arrow in TikZ diff --git a/src/nl/hannahsten/texifyidea/util/parser/Psi.kt b/src/nl/hannahsten/texifyidea/util/parser/Psi.kt index 8eb6e45cd..a8eeb09f4 100644 --- a/src/nl/hannahsten/texifyidea/util/parser/Psi.kt +++ b/src/nl/hannahsten/texifyidea/util/parser/Psi.kt @@ -96,7 +96,7 @@ fun PsiElement.firstParentOfType(clazz: KClass): T? { if (clazz.java.isAssignableFrom(current.javaClass)) { return current as? T } - current = current.parent + current = current.parent?.let { if (it.isValid) it else null } } return null } @@ -108,7 +108,7 @@ inline fun PsiElement.firstParentOfType(): T? { if (current is T) { return current } - current = current.parent + current = current.parent?.let { if (it.isValid) it else null } } return null }