Skip to content

Commit e2909f9

Browse files
Add autocompleteBraces behavior setting
Adds a new 'autocompleteBraces' option to the Behavior configuration that controls whether opening brackets automatically insert their closing pair. When disabled, typing '{' will only insert '{' without the automatic '}'. This enables downstream editors like CodeEdit to respect user preferences for bracket auto-completion. Changes: - Add autocompleteBraces property to Behavior struct (default: true) - Conditionally set up OpenPairFilter and DeletePairFilter based on setting - Trigger setUpTextFormation when setting changes
1 parent 1fa4d3c commit e2909f9

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Sources/CodeEditSourceEditor/Controller/TextViewController+TextFormation.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ extension TextViewController {
1919

2020
// Filters
2121

22-
setUpOpenPairFilters(pairs: BracketPairs.allValues)
22+
// Only set up bracket pair completion if enabled in settings
23+
if configuration.behavior.autocompleteBraces {
24+
setUpOpenPairFilters(pairs: BracketPairs.allValues)
25+
setUpDeletePairFilters(pairs: BracketPairs.allValues)
26+
}
27+
2328
setUpTagFilter()
2429
setUpNewlineTabFilters(indentOption: configuration.behavior.indentOption)
25-
setUpDeletePairFilters(pairs: BracketPairs.allValues)
2630
setUpDeleteWhitespaceFilter(indentOption: configuration.behavior.indentOption)
2731
}
2832

Sources/CodeEditSourceEditor/SourceEditorConfiguration/SourceEditorConfiguration+Behavior.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,22 @@ extension SourceEditorConfiguration {
2020
/// The column to reformat at.
2121
public var reformatAtColumn: Int = 80
2222

23+
/// Controls whether opening brackets automatically insert their closing pair.
24+
/// When true, typing `{` will automatically insert `}` and position the cursor between them.
25+
public var autocompleteBraces: Bool = true
26+
2327
public init(
2428
isEditable: Bool = true,
2529
isSelectable: Bool = true,
2630
indentOption: IndentOption = .spaces(count: 4),
27-
reformatAtColumn: Int = 80
31+
reformatAtColumn: Int = 80,
32+
autocompleteBraces: Bool = true
2833
) {
2934
self.isEditable = isEditable
3035
self.isSelectable = isSelectable
3136
self.indentOption = indentOption
3237
self.reformatAtColumn = reformatAtColumn
38+
self.autocompleteBraces = autocompleteBraces
3339
}
3440

3541
@MainActor
@@ -48,7 +54,7 @@ extension SourceEditorConfiguration {
4854
controller.textView.isSelectable = isSelectable
4955
}
5056

51-
if oldConfig?.indentOption != indentOption {
57+
if oldConfig?.indentOption != indentOption || oldConfig?.autocompleteBraces != autocompleteBraces {
5258
controller.setUpTextFormation()
5359
}
5460

0 commit comments

Comments
 (0)