diff --git a/Sources/CodeEditSourceEditor/Controller/TextViewController+TextFormation.swift b/Sources/CodeEditSourceEditor/Controller/TextViewController+TextFormation.swift index b98ad44f4..95d4d7093 100644 --- a/Sources/CodeEditSourceEditor/Controller/TextViewController+TextFormation.swift +++ b/Sources/CodeEditSourceEditor/Controller/TextViewController+TextFormation.swift @@ -19,11 +19,14 @@ extension TextViewController { // Filters - setUpOpenPairFilters(pairs: BracketPairs.allValues) + if configuration.behavior.autocompleteBraces { + setUpOpenPairFilters(pairs: BracketPairs.allValues) + setUpDeletePairFilters(pairs: BracketPairs.allValues) + } setUpTagFilter() setUpNewlineTabFilters(indentOption: configuration.behavior.indentOption) - setUpDeletePairFilters(pairs: BracketPairs.allValues) setUpDeleteWhitespaceFilter(indentOption: configuration.behavior.indentOption) + } /// Returns a `TextualIndenter` based on available language configuration. diff --git a/Sources/CodeEditSourceEditor/SourceEditorConfiguration/SourceEditorConfiguration+Behavior.swift b/Sources/CodeEditSourceEditor/SourceEditorConfiguration/SourceEditorConfiguration+Behavior.swift index 28255f14d..7ade2f9c2 100644 --- a/Sources/CodeEditSourceEditor/SourceEditorConfiguration/SourceEditorConfiguration+Behavior.swift +++ b/Sources/CodeEditSourceEditor/SourceEditorConfiguration/SourceEditorConfiguration+Behavior.swift @@ -14,6 +14,9 @@ extension SourceEditorConfiguration { /// false, the editor is selectable but not editable. public var isSelectable: Bool = true + /// Controls whether opening brackets/braces are automatically completed with their closing counterpart. + public var autocompleteBraces: Bool = true + /// Determines what character(s) to insert when the tab key is pressed. Defaults to 4 spaces. public var indentOption: IndentOption = .spaces(count: 4) @@ -23,11 +26,13 @@ extension SourceEditorConfiguration { public init( isEditable: Bool = true, isSelectable: Bool = true, + autocompleteBraces: Bool = true, indentOption: IndentOption = .spaces(count: 4), reformatAtColumn: Int = 80 ) { self.isEditable = isEditable self.isSelectable = isSelectable + self.autocompleteBraces = autocompleteBraces self.indentOption = indentOption self.reformatAtColumn = reformatAtColumn } @@ -48,7 +53,7 @@ extension SourceEditorConfiguration { controller.textView.isSelectable = isSelectable } - if oldConfig?.indentOption != indentOption { + if oldConfig?.indentOption != indentOption || oldConfig?.autocompleteBraces != autocompleteBraces { controller.setUpTextFormation() }