From 7e2eaaa9337c1ccfe7b568d8385bbfdf74347e89 Mon Sep 17 00:00:00 2001 From: William Laverty Date: Sun, 15 Feb 2026 01:03:31 -0800 Subject: [PATCH] Add autocompleteBraces setting to Behavior configuration The autocompleteBraces setting existed in CodeEdit's preferences but was never passed through to the source editor. This adds the setting to the Behavior configuration struct and conditionally sets up bracket pair filters based on its value. When autocompleteBraces is false, both the open pair filters and delete pair filters are skipped, preventing automatic insertion of closing brackets. Fixes CodeEditApp/CodeEdit#1691 --- .../Controller/TextViewController+TextFormation.swift | 7 +++++-- .../SourceEditorConfiguration+Behavior.swift | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) 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() }