diff --git a/CHANGELOG.md b/CHANGELOG.md index d7b719f61..26b9b2944 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased] ### Added +* Do not fold sections in a command definition * Include optional parameters in spellcheck, if it contains text ### Fixed diff --git a/src/nl/hannahsten/texifyidea/editor/folding/LatexSectionFoldingBuilder.kt b/src/nl/hannahsten/texifyidea/editor/folding/LatexSectionFoldingBuilder.kt index 0faa43f9f..d5fc0f27c 100644 --- a/src/nl/hannahsten/texifyidea/editor/folding/LatexSectionFoldingBuilder.kt +++ b/src/nl/hannahsten/texifyidea/editor/folding/LatexSectionFoldingBuilder.kt @@ -9,10 +9,7 @@ import com.intellij.psi.PsiElement import nl.hannahsten.texifyidea.lang.magic.DefaultMagicKeys import nl.hannahsten.texifyidea.psi.* import nl.hannahsten.texifyidea.util.magic.CommandMagic -import nl.hannahsten.texifyidea.util.parser.childrenOfType -import nl.hannahsten.texifyidea.util.parser.nextSiblingIgnoreWhitespace -import nl.hannahsten.texifyidea.util.parser.parentOfType -import nl.hannahsten.texifyidea.util.parser.previousSiblingIgnoreWhitespace +import nl.hannahsten.texifyidea.util.parser.* /** * Recursively folds section commands @@ -31,6 +28,10 @@ open class LatexSectionFoldingBuilder : FoldingBuilderEx() { override fun buildFoldRegions(root: PsiElement, document: Document, quick: Boolean): Array { val descriptors = ArrayList() val commands = root.childrenOfType().filter { it.name in sectionCommands } + // If it has no parameters, it is probably not an actual section but in a command definition + .filter { it.parameterList.isNotEmpty() } + // Similarly, if the section command is in a parameter it is probably in the preamble, and we should not fold + .filter { it.firstParentOfType() == null } .sortedBy { it.textOffset } val comments = root.childrenOfType().filter { it.key() == DefaultMagicKeys.FAKE } val sectionElements: List = (commands + comments).sortedBy { it.textOffset } diff --git a/src/nl/hannahsten/texifyidea/editor/postfix/LatexStringBasedPostfixTemplates.kt b/src/nl/hannahsten/texifyidea/editor/postfix/LatexStringBasedPostfixTemplates.kt index f8361c6f5..40f23e270 100644 --- a/src/nl/hannahsten/texifyidea/editor/postfix/LatexStringBasedPostfixTemplates.kt +++ b/src/nl/hannahsten/texifyidea/editor/postfix/LatexStringBasedPostfixTemplates.kt @@ -63,6 +63,8 @@ internal object LatexWrapWithMathbbPostfixTemplate : LatexWrapWithCommandPostfix internal object LatexWrapWithBmPostfixTemplate : LatexWrapWithCommandPostfixTemplate("bm", mathOnly = true, pack = LatexPackage.BM) internal object LatexWrapWithMathcalPostfixTemplate : LatexWrapWithCommandPostfixTemplate("mathcal", name = "cal", mathOnly = true) +// Not actually a postfix template, just a base class +@Suppress("PostfixTemplateDescriptionNotFound") internal open class LatexWrapWithCommandPostfixTemplate(commandName: String, name: String = commandName, mathOnly: Boolean = false, textOnly: Boolean = false, pack: LatexPackage? = null) : ConstantStringBasedPostfixTemplate( name, "\\$commandName{expr}", diff --git a/src/nl/hannahsten/texifyidea/editor/postfix/editable/LatexEditablePostfixTemplate.kt b/src/nl/hannahsten/texifyidea/editor/postfix/editable/LatexEditablePostfixTemplate.kt index 0499efd4d..885fdf414 100644 --- a/src/nl/hannahsten/texifyidea/editor/postfix/editable/LatexEditablePostfixTemplate.kt +++ b/src/nl/hannahsten/texifyidea/editor/postfix/editable/LatexEditablePostfixTemplate.kt @@ -7,6 +7,7 @@ import com.intellij.psi.PsiElement import nl.hannahsten.texifyidea.editor.postfix.LatexPostFixTemplateProvider import nl.hannahsten.texifyidea.editor.postfix.LatexPostfixExpressionSelector +@Suppress("PostfixTemplateDescriptionNotFound") class LatexEditablePostfixTemplate(templateId: String, templateName: String, template: TemplateImpl, conditions: Set, provider: LatexPostFixTemplateProvider) : EditablePostfixTemplateWithMultipleExpressions(templateId, templateName, template, "", conditions, true, provider) { diff --git a/src/nl/hannahsten/texifyidea/gutter/LatexCompileGutter.kt b/src/nl/hannahsten/texifyidea/gutter/LatexCompileGutter.kt index 316a04eec..8ea8863ed 100644 --- a/src/nl/hannahsten/texifyidea/gutter/LatexCompileGutter.kt +++ b/src/nl/hannahsten/texifyidea/gutter/LatexCompileGutter.kt @@ -3,6 +3,7 @@ package nl.hannahsten.texifyidea.gutter import com.intellij.execution.lineMarker.ExecutorAction import com.intellij.execution.lineMarker.RunLineMarkerContributor import com.intellij.openapi.actionSystem.ActionManager +import com.intellij.openapi.actionSystem.IdeActions import com.intellij.psi.PsiElement import nl.hannahsten.texifyidea.TexifyIcons import nl.hannahsten.texifyidea.psi.LatexBeginCommand @@ -29,7 +30,7 @@ class LatexCompileGutter : RunLineMarkerContributor() { // Lookup actions. val actionManager = ActionManager.getInstance() - val editConfigs = actionManager.getAction("editRunConfigurations") + val editConfigs = actionManager.getAction(IdeActions.ACTION_EDIT_RUN_CONFIGURATIONS) val actions = ExecutorAction.getActions(0) // Create icon. diff --git a/test/resources/editor/folding/sections.tex b/test/resources/editor/folding/sections.tex index 6a7085618..b62862a3c 100644 --- a/test/resources/editor/folding/sections.tex +++ b/test/resources/editor/folding/sections.tex @@ -1,3 +1,4 @@ +\titleformat*{\section}{\itshape} \begin{document} \section{One} Text.