Skip to content

Commit

Permalink
Add folding settings for all folding builders
Browse files Browse the repository at this point in the history
  • Loading branch information
PHPirates committed Jan 18, 2024
1 parent 8862903 commit 4f01517
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class LatexCodeFoldingOptionsProvider : CodeFoldingOptionsProvider, BeanConfigur
val settings = instance
if (settings != null) {
checkBox("Package imports", settings::collapseImports)
checkBox("Environments", settings::foldEnvironments)
checkBox("Escaped symbols", settings::foldEscapedSymbols)
checkBox("Footnotes", settings::foldFootnotes)
checkBox("Math symbols", settings::foldMathSymbols)
checkBox("Sections", settings::foldSections)
checkBox("Symbols", settings::foldSymbols)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ import com.intellij.util.xmlb.XmlSerializerUtil
@State(name = "LatexCodeFoldingSettings", storages = [Storage("editor.xml")])
class LatexCodeFoldingSettings : PersistentStateComponent<LatexCodeFoldingSettings> {

var collapseImports: Boolean = true
var collapseImports = true
var foldEnvironments = false
var foldEscapedSymbols = true
var foldFootnotes = true
var foldMathSymbols = true
var foldSections = false
var foldSymbols = true

override fun getState() = this

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import nl.hannahsten.texifyidea.util.parser.endOffset
*/
class LatexEnvironmentFoldingBuilder : FoldingBuilderEx(), DumbAware {

override fun isCollapsedByDefault(node: ASTNode) = false
override fun isCollapsedByDefault(node: ASTNode) = LatexCodeFoldingSettings.getInstance().foldEnvironments

override fun getPlaceholderText(node: ASTNode) = "..."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import nl.hannahsten.texifyidea.util.files.commandsInFile
*/
class LatexEscapedSymbolFoldingBuilder : FoldingBuilderEx(), DumbAware {

override fun isCollapsedByDefault(node: ASTNode) = true
override fun isCollapsedByDefault(node: ASTNode) = LatexCodeFoldingSettings.getInstance().foldEscapedSymbols

override fun getPlaceholderText(node: ASTNode): String? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import com.intellij.refactoring.suggested.endOffset
import com.intellij.refactoring.suggested.startOffset
import nl.hannahsten.texifyidea.psi.LatexCommands
import nl.hannahsten.texifyidea.psi.LatexRequiredParam
import nl.hannahsten.texifyidea.util.magic.CommandMagic.foldableFootnotes
import nl.hannahsten.texifyidea.util.parser.childrenOfType
import nl.hannahsten.texifyidea.util.parser.firstChildOfType
import nl.hannahsten.texifyidea.util.magic.CommandMagic.foldableFootnotes

/**
* Adds folding regions for LaTeX environments.
Expand All @@ -24,7 +24,7 @@ import nl.hannahsten.texifyidea.util.magic.CommandMagic.foldableFootnotes
*/
class LatexFootnoteFoldingBuilder : FoldingBuilderEx(), DumbAware {

override fun isCollapsedByDefault(node: ASTNode) = true
override fun isCollapsedByDefault(node: ASTNode) = LatexCodeFoldingSettings.getInstance().foldFootnotes

override fun getPlaceholderText(node: ASTNode): String {
val parsedText = node.text.substring(1).trim()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LatexMathSymbolFoldingBuilder : FoldingBuilderEx(), DumbAware {
return descriptors.toTypedArray()
}

override fun isCollapsedByDefault(node: ASTNode) = true
override fun isCollapsedByDefault(node: ASTNode) = LatexCodeFoldingSettings.getInstance().foldMathSymbols

override fun getPlaceholderText(node: ASTNode): String? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ open class LatexSectionFoldingBuilder : FoldingBuilderEx() {
private val sectionCommandNames = CommandMagic.sectioningCommands.map { it.command }
private val sectionCommands = sectionCommandNames.map { "\\$it" }.toTypedArray()

override fun isCollapsedByDefault(node: ASTNode) = false
override fun isCollapsedByDefault(node: ASTNode) = LatexCodeFoldingSettings.getInstance().foldSections

override fun getPlaceholderText(node: ASTNode) = node.text + "..."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import nl.hannahsten.texifyidea.util.toTextRange
*/
class LatexSymbolFoldingBuilder : FoldingBuilderEx(), DumbAware {

override fun isCollapsedByDefault(node: ASTNode) = true
override fun isCollapsedByDefault(node: ASTNode) = LatexCodeFoldingSettings.getInstance().foldSymbols

override fun getPlaceholderText(node: ASTNode): String? = null

Expand Down

0 comments on commit 4f01517

Please sign in to comment.