diff --git a/Sources/CodeEditSourceEditor/Controller/TextViewController+TextFormation.swift b/Sources/CodeEditSourceEditor/Controller/TextViewController+TextFormation.swift index b98ad44f4..a447ce1af 100644 --- a/Sources/CodeEditSourceEditor/Controller/TextViewController+TextFormation.swift +++ b/Sources/CodeEditSourceEditor/Controller/TextViewController+TextFormation.swift @@ -19,10 +19,14 @@ extension TextViewController { // Filters - setUpOpenPairFilters(pairs: BracketPairs.allValues) + // Only set up bracket pair completion if enabled in settings + 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) } diff --git a/Sources/CodeEditSourceEditor/SourceEditorConfiguration/SourceEditorConfiguration+Behavior.swift b/Sources/CodeEditSourceEditor/SourceEditorConfiguration/SourceEditorConfiguration+Behavior.swift index 28255f14d..b61096a25 100644 --- a/Sources/CodeEditSourceEditor/SourceEditorConfiguration/SourceEditorConfiguration+Behavior.swift +++ b/Sources/CodeEditSourceEditor/SourceEditorConfiguration/SourceEditorConfiguration+Behavior.swift @@ -20,16 +20,22 @@ extension SourceEditorConfiguration { /// The column to reformat at. public var reformatAtColumn: Int = 80 + /// Controls whether opening brackets automatically insert their closing pair. + /// When true, typing `{` will automatically insert `}` and position the cursor between them. + public var autocompleteBraces: Bool = true + public init( isEditable: Bool = true, isSelectable: Bool = true, indentOption: IndentOption = .spaces(count: 4), - reformatAtColumn: Int = 80 + reformatAtColumn: Int = 80, + autocompleteBraces: Bool = true ) { self.isEditable = isEditable self.isSelectable = isSelectable self.indentOption = indentOption self.reformatAtColumn = reformatAtColumn + self.autocompleteBraces = autocompleteBraces } @MainActor @@ -48,7 +54,7 @@ extension SourceEditorConfiguration { controller.textView.isSelectable = isSelectable } - if oldConfig?.indentOption != indentOption { + if oldConfig?.indentOption != indentOption || oldConfig?.autocompleteBraces != autocompleteBraces { controller.setUpTextFormation() }