-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Indent wrapped lines (CodeEditTextView #18): settings, UI, tests; git… #2158
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,6 +18,7 @@ extension SettingsData { | |||||||||||||||||||
| "Prefer Indent Using", | ||||||||||||||||||||
| "Tab Width", | ||||||||||||||||||||
| "Wrap lines to editor width", | ||||||||||||||||||||
| "Indent wrapped lines", | ||||||||||||||||||||
| "Editor Overscroll", | ||||||||||||||||||||
| "Font", | ||||||||||||||||||||
| "Font Size", | ||||||||||||||||||||
|
|
@@ -60,6 +61,11 @@ extension SettingsData { | |||||||||||||||||||
| /// A flag indicating whether to wrap lines to editor width | ||||||||||||||||||||
| var wrapLinesToEditorWidth: Bool = true | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /// Spaces to indent continuation lines when line wrapping | ||||||||||||||||||||
| /// is on (e.g. 4 or 12). See: | ||||||||||||||||||||
| /// https://github.com/CodeEditApp/CodeEditTextView/issues/18 | ||||||||||||||||||||
| var wrappedLineIndent: Int = 4 | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /// The percentage of overscroll to apply to the text view | ||||||||||||||||||||
| var overscroll: OverscrollOption = .medium | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -122,6 +128,10 @@ extension SettingsData { | |||||||||||||||||||
| Bool.self, | ||||||||||||||||||||
| forKey: .wrapLinesToEditorWidth | ||||||||||||||||||||
| ) ?? true | ||||||||||||||||||||
| self.wrappedLineIndent = try container.decodeIfPresent( | ||||||||||||||||||||
| Int.self, | ||||||||||||||||||||
| forKey: .wrappedLineIndent | ||||||||||||||||||||
| ) ?? 4 | ||||||||||||||||||||
|
Comment on lines
+131
to
+134
|
||||||||||||||||||||
| self.wrappedLineIndent = try container.decodeIfPresent( | |
| Int.self, | |
| forKey: .wrappedLineIndent | |
| ) ?? 4 | |
| let decodedWrappedLineIndent = try container.decodeIfPresent( | |
| Int.self, | |
| forKey: .wrappedLineIndent | |
| ) ?? 4 | |
| self.wrappedLineIndent = min(max(decodedWrappedLineIndent, 0), 24) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,7 +75,8 @@ extension GitClient { | |
| case "!", "#": // Ignored files or Header | ||
| try substringToNextNull(from: &index, output: output) // move the index to the next line. | ||
| default: | ||
| throw GitClientError.statusInvalidChangeType(output[typeIndex]) | ||
| // Skip unknown entry types (e.g. future porcelain v2 types or unexpected output) | ||
| try substringToNextNull(from: &index, output: output) | ||
|
Comment on lines
77
to
+79
|
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // | ||
| // TextEditingSettingsTests.swift | ||
| // CodeEditTests | ||
| // | ||
| // Tests for Text Editing settings, including wrapped line indent (CodeEditTextView #18). | ||
| // | ||
|
|
||
| import Foundation | ||
| import Testing | ||
| @testable import CodeEdit | ||
|
|
||
| @Suite("Text Editing Settings") | ||
| struct TextEditingSettingsTests { | ||
|
|
||
| // MARK: - Wrapped line indent (indent wrapped lines - CodeEditTextView #18) | ||
|
|
||
| @Test("Default wrapped line indent is 4 spaces") | ||
| func defaultWrappedLineIndentIsFour() { | ||
| let settings = SettingsData.TextEditingSettings() | ||
| #expect(settings.wrappedLineIndent == 4) | ||
| } | ||
|
|
||
| @Test("Wrapped line indent round-trips through Codable") | ||
| func wrappedLineIndentRoundTrips() throws { | ||
| var settings = SettingsData.TextEditingSettings() | ||
| settings.wrappedLineIndent = 12 | ||
|
|
||
| let encoded = try JSONEncoder().encode(settings) | ||
| let decoded = try JSONDecoder().decode(SettingsData.TextEditingSettings.self, from: encoded) | ||
| #expect(decoded.wrappedLineIndent == 12) | ||
| } | ||
|
|
||
| @Test("Decode with missing wrappedLineIndent uses default 4") | ||
| func decodeMissingWrappedLineIndentUsesDefault() throws { | ||
| // JSON without wrappedLineIndent key (e.g. existing user preferences) | ||
| let json = """ | ||
| {"wrapLinesToEditorWidth": true} | ||
| """ | ||
| let data = json.data(using: .utf8)! | ||
| // Decode a minimal object; TextEditingSettings init(from:) decodes each key with default | ||
| let decoded = try JSONDecoder().decode(SettingsData.TextEditingSettings.self, from: data) | ||
| #expect(decoded.wrappedLineIndent == 4) | ||
| } | ||
|
|
||
| @Test("Wrapped line indent accepts valid range 0–24") | ||
| func wrappedLineIndentValidRange() throws { | ||
| for value in [0, 4, 8, 12, 24] { | ||
| var settings = SettingsData.TextEditingSettings() | ||
| settings.wrappedLineIndent = value | ||
| let encoded = try JSONEncoder().encode(settings) | ||
| let decoded = try JSONDecoder().decode(SettingsData.TextEditingSettings.self, from: encoded) | ||
| #expect(decoded.wrappedLineIndent == value) | ||
| } | ||
| } | ||
|
Comment on lines
+45
to
+54
|
||
|
|
||
| @Test("Wrap lines to editor width default is true") | ||
| func wrapLinesToEditorWidthDefault() { | ||
| let settings = SettingsData.TextEditingSettings() | ||
| #expect(settings.wrapLinesToEditorWidth == true) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation comment spans multiple lines but doesn't follow the standard Swift documentation format. In the codebase, similar properties use single-line comments (see lines 45-46, 52-53, 55-56, 58-59, 61-62, 69-70). Consider condensing to a single-line comment for consistency, or if the reference is important, format it as a proper multi-line doc comment with proper indentation on continuation lines.