Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some newline issues in enumeration #3383

Merged
merged 5 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import com.intellij.openapi.util.Ref
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.util.parentOfType
import com.intellij.psi.util.parentOfTypes
import com.jetbrains.rd.util.first
import nl.hannahsten.texifyidea.file.LatexFileType
import nl.hannahsten.texifyidea.psi.*
import nl.hannahsten.texifyidea.settings.TexifySettings
Expand Down Expand Up @@ -71,7 +74,7 @@
*/
private fun getPreviousMarker(element: PsiElement): String? {
val environment = element.parentOfType(LatexEnvironment::class) ?: return null

Check warning on line 77 in src/nl/hannahsten/texifyidea/editor/typedhandlers/LatexEnterInEnumerationHandler.kt

View workflow job for this annotation

GitHub Actions / Qodana

Usage of redundant or deprecated syntax or deprecated symbols

'parentOfType(vararg KClass): T?' is deprecated. Use parentOfTypes()
// Last element in the list => Find last \item.
val label = if (element.parent is LatexEnvironment) {
getLastLabel(environment)
Expand All @@ -82,8 +85,11 @@
} ?: return null // when no label could befound.

// Extract optional parameters.
val optionals = label.childrenOfType(LatexOptionalParam::class).firstOrNull() ?: return null
return optionals.text
val paramMap = label.getOptionalParameterMap()
if (paramMap.isEmpty())
return null
else
return paramMap.first().key.text ?: return null
}

/**
Expand Down Expand Up @@ -141,6 +147,12 @@

val isGluedToTheBeginCommand = element.hasParent(LatexBeginCommand::class)
val isInsideAnEnumeration = element.inDirectEnvironment(EnvironmentMagic.listingEnvironments)
return isInsideAnEnumeration && !isGluedToTheBeginCommand
val environment = element.parentOfTypes(LatexEnvironment::class)
val isInsideRequiredParam =
Fixed Show fixed Hide fixed
if (environment != null)
element.firstParentOfType(LatexRequiredParam::class)?.isChildOf(getLastLabel(environment)) ?: false
PHPirates marked this conversation as resolved.
Show resolved Hide resolved
else
false
return isInsideAnEnumeration && !isGluedToTheBeginCommand && !isInsideRequiredParam
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,46 @@ class LatexEnterInEnumerationHandlerTest : BasePlatformTestCase() {
)
}

fun testItemizeBreakLine() {
myFixture.configureByText(
LatexFileType,
"""
\begin{itemize}
\item This sentence is <caret>broken
\end{itemize}
""".trimIndent()
)
myFixture.type("\n")
myFixture.checkResult(
"""
\begin{itemize}
\item This sentence is
\item <caret>broken
\end{itemize}
""".trimIndent()
)
}

fun testItemizeBreakLineNoItem() {
myFixture.configureByText(
LatexFileType,
"""
\begin{itemize}
\item {This sentence is <caret>broken}
\end{itemize}
""".trimIndent()
)
myFixture.type("\n")
myFixture.checkResult(
"""
\begin{itemize}
\item {This sentence is
<caret>broken}
\end{itemize}
""".trimIndent()
)
}

fun `test nested enumeration with prefix`() {
myFixture.configureByText(
LatexFileType,
Expand Down
Loading