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

Do not fold sections in a command definition #3804

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
* Do not fold sections in a command definition
* Include optional parameters in spellcheck, if it contains text

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,6 +28,10 @@ open class LatexSectionFoldingBuilder : FoldingBuilderEx() {
override fun buildFoldRegions(root: PsiElement, document: Document, quick: Boolean): Array<FoldingDescriptor> {
val descriptors = ArrayList<FoldingDescriptor>()
val commands = root.childrenOfType<LatexCommands>().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<LatexParameter>() == null }
.sortedBy { it.textOffset }
val comments = root.childrenOfType<LatexMagicComment>().filter { it.key() == DefaultMagicKeys.FAKE }
val sectionElements: List<PsiElement> = (commands + comments).sortedBy { it.textOffset }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<LatexPostfixTemplateExpressionCondition>, provider: LatexPostFixTemplateProvider) :
EditablePostfixTemplateWithMultipleExpressions<LatexPostfixTemplateExpressionCondition>(templateId, templateName, template, "", conditions, true, provider) {

Expand Down
3 changes: 2 additions & 1 deletion src/nl/hannahsten/texifyidea/gutter/LatexCompileGutter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions test/resources/editor/folding/sections.tex
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
\titleformat*{\section}{\itshape}
\begin{document}<fold text='...'>
<fold text='\section{One}...'>\section{One}
Text.
Expand Down
Loading