Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preference for text wrapping in editor, add command palette options for text editing prefs #948

Merged
2 changes: 1 addition & 1 deletion CodeEdit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3284,7 +3284,7 @@
repositoryURL = "https://github.com/CodeEditApp/CodeEditTextView.git";
requirement = {
kind = exactVersion;
version = 0.2.2;
version = 0.3.0;
};
};
58F2EB18292FB91C004A9BDE /* XCRemoteSwiftPackageReference "Preferences" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/CodeEditApp/CodeEditLanguages.git",
"state" : {
"revision" : "9f107a5d9a4da49075dcdc288b5e69527a9e5a64",
"version" : "0.1.5"
"revision" : "e7334f4f1c1495d88d663a92e0d1ebcbbcdb0550",
"version" : "0.1.6"
}
},
{
Expand All @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/CodeEditApp/CodeEditTextView.git",
"state" : {
"revision" : "f7883bbb6bb51e3f2bcfe0453014d0b07f4f932b",
"version" : "0.2.2"
"revision" : "c3eb00c66f09a8b54cda47ee9a7111bb79e67f42",
"version" : "0.3.0"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ extension AppPreferences {

var autocompleteBraces: Bool = true

// A flag indicating whether to wrap lines to editor width
var wrapLinesToEditorWidth: Bool = true
ben-p-commits marked this conversation as resolved.
Show resolved Hide resolved

/// Default initializer
init() {}
init() {
self.populateCommands()
}

/// Explicit decoder init for setting default values when key is not present in `JSON`
init(from decoder: Decoder) throws {
Expand All @@ -33,6 +38,38 @@ extension AppPreferences {
Bool.self, forKey: .enableTypeOverCompletion) ?? true
self.autocompleteBraces = try container.decodeIfPresent(Bool.self,
forKey: .autocompleteBraces) ?? true
self.wrapLinesToEditorWidth = try container.decodeIfPresent(Bool.self,
forKey: .wrapLinesToEditorWidth) ?? true
self.populateCommands()
}

/// Adds toggle-able preferences to the command palette via shared `CommandManager`
private func populateCommands() {
let mgr = CommandManager.shared

mgr.addCommand(
name: "Toggle Type-Over Completion",
title: "Toggle Type-Over Completion",
id: "prefs.text_editing.type_over_completion",
command: CommandClosureWrapper {
AppPreferencesModel.shared.preferences.textEditing.enableTypeOverCompletion.toggle()
})

mgr.addCommand(
name: "Toggle Autocomplete Braces",
title: "Toggle Autocomplete Braces",
id: "prefs.text_editing.autocomplete_braces",
command: CommandClosureWrapper {
AppPreferencesModel.shared.preferences.textEditing.autocompleteBraces.toggle()
})

mgr.addCommand(
name: "Toggle Word Wrap",
title: "Toggle Word Wrap",
id: "prefs.text_editing.wrap_lines_to_editor_width",
command: CommandClosureWrapper {
AppPreferencesModel.shared.preferences.textEditing.wrapLinesToEditorWidth.toggle()
})
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ struct TextEditingPreferencesView: View {
autocompleteBraces
enableTypeOverCompletion
}
PreferencesSection("Line Wrapping") {
wrapLinesToEditorWidth
}
}
}

Expand Down Expand Up @@ -75,4 +78,12 @@ struct TextEditingPreferencesView: View {
Text("Enable type-over completion")
}
}

private var wrapLinesToEditorWidth: some View {
HStack {
Toggle("Wrap lines to editor width", isOn: $prefs.preferences.textEditing.wrapLinesToEditorWidth)
Text("Wrap lines to editor width")
}
}

}
1 change: 1 addition & 0 deletions CodeEdit/Features/CodeFile/CodeFileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct CodeFileView: View {
font: $font,
tabWidth: $prefs.preferences.textEditing.defaultTabWidth,
lineHeight: .constant(1.2), // TODO: Add to preferences
wrapLines: $prefs.preferences.textEditing.wrapLinesToEditorWidth,
cursorPosition: codeFile.$cursorPosition
)
.id(codeFile.fileURL)
Expand Down
2 changes: 1 addition & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/CodeEditApp/CodeEditTextView.git",
"state" : {
"revision" : "7e9bb803e6892d5cd5380edaf6bdefa24628edb1",
"revision" : "e3c93a2285ad3b9b5294adf205ce7a8518a74f8a",
"version" : "0.1.5"
}
},
Expand Down