Skip to content

Commit 7e2eaaa

Browse files
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
1 parent 1fa4d3c commit 7e2eaaa

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Sources/CodeEditSourceEditor/Controller/TextViewController+TextFormation.swift

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

2020
// Filters
2121

22-
setUpOpenPairFilters(pairs: BracketPairs.allValues)
22+
if configuration.behavior.autocompleteBraces {
23+
setUpOpenPairFilters(pairs: BracketPairs.allValues)
24+
setUpDeletePairFilters(pairs: BracketPairs.allValues)
25+
}
2326
setUpTagFilter()
2427
setUpNewlineTabFilters(indentOption: configuration.behavior.indentOption)
25-
setUpDeletePairFilters(pairs: BracketPairs.allValues)
2628
setUpDeleteWhitespaceFilter(indentOption: configuration.behavior.indentOption)
29+
2730
}
2831

2932
/// Returns a `TextualIndenter` based on available language configuration.

Sources/CodeEditSourceEditor/SourceEditorConfiguration/SourceEditorConfiguration+Behavior.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ extension SourceEditorConfiguration {
1414
/// false, the editor is selectable but not editable.
1515
public var isSelectable: Bool = true
1616

17+
/// Controls whether opening brackets/braces are automatically completed with their closing counterpart.
18+
public var autocompleteBraces: Bool = true
19+
1720
/// Determines what character(s) to insert when the tab key is pressed. Defaults to 4 spaces.
1821
public var indentOption: IndentOption = .spaces(count: 4)
1922

@@ -23,11 +26,13 @@ extension SourceEditorConfiguration {
2326
public init(
2427
isEditable: Bool = true,
2528
isSelectable: Bool = true,
29+
autocompleteBraces: Bool = true,
2630
indentOption: IndentOption = .spaces(count: 4),
2731
reformatAtColumn: Int = 80
2832
) {
2933
self.isEditable = isEditable
3034
self.isSelectable = isSelectable
35+
self.autocompleteBraces = autocompleteBraces
3136
self.indentOption = indentOption
3237
self.reformatAtColumn = reformatAtColumn
3338
}
@@ -48,7 +53,7 @@ extension SourceEditorConfiguration {
4853
controller.textView.isSelectable = isSelectable
4954
}
5055

51-
if oldConfig?.indentOption != indentOption {
56+
if oldConfig?.indentOption != indentOption || oldConfig?.autocompleteBraces != autocompleteBraces {
5257
controller.setUpTextFormation()
5358
}
5459

0 commit comments

Comments
 (0)