Skip to content

Commit 5b86971

Browse files
authored
Merge pull request #955 from ben-p-commits/line-height-preference
Add line height multiple option to text editing preferences
2 parents 0b85221 + fb9a969 commit 5b86971

3 files changed

Lines changed: 39 additions & 4 deletions

File tree

CodeEdit/Features/AppPreferences/Model/Text Editing/TextEditingPreferences.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ extension AppPreferences {
1717
/// The font to use in editor.
1818
var font: EditorFont = .init()
1919

20+
/// A flag indicating whether type-over completion is enabled
2021
var enableTypeOverCompletion: Bool = true
2122

23+
/// A flag indicating whether braces are automatically completed
2224
var autocompleteBraces: Bool = true
2325

24-
// A flag indicating whether to wrap lines to editor width
26+
/// A flag indicating whether to wrap lines to editor width
2527
var wrapLinesToEditorWidth: Bool = true
2628

29+
/// A multiplier for setting the line height. Defaults to `1.45`
30+
var lineHeightMultiple: Double = 1.45
31+
2732
/// Default initializer
2833
init() {
2934
self.populateCommands()
@@ -40,6 +45,9 @@ extension AppPreferences {
4045
forKey: .autocompleteBraces) ?? true
4146
self.wrapLinesToEditorWidth = try container.decodeIfPresent(Bool.self,
4247
forKey: .wrapLinesToEditorWidth) ?? true
48+
self.lineHeightMultiple = try container.decodeIfPresent(Double.self,
49+
forKey: .lineHeightMultiple) ?? 1.45
50+
4351
self.populateCommands()
4452
}
4553

CodeEdit/Features/AppPreferences/Sections/TextEditingPreferences/TextEditingPreferencesView.swift

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct TextEditingPreferencesView: View {
1313
private var prefs: AppPreferencesModel = .shared
1414

1515
/// only allows integer values in the range of `[1...8]`
16-
private var numberFormat: NumberFormatter {
16+
private var tabWidthFormatter: NumberFormatter {
1717
let formatter = NumberFormatter()
1818
formatter.allowsFloats = false
1919
formatter.minimum = 1
@@ -22,11 +22,24 @@ struct TextEditingPreferencesView: View {
2222
return formatter
2323
}
2424

25+
/// only allows float values in the range of `[0.75...2.00]`
26+
/// and formats to 2 decimal places.
27+
private var lineHeightFormatter: NumberFormatter {
28+
let formatter = NumberFormatter()
29+
formatter.allowsFloats = true
30+
formatter.maximumFractionDigits = 2
31+
formatter.minimumFractionDigits = 2
32+
formatter.minimum = 0.75
33+
formatter.maximum = 2.0
34+
35+
return formatter
36+
}
37+
2538
var body: some View {
2639
PreferencesContent {
2740
PreferencesSection("Default Tab Width") {
2841
HStack(spacing: 5) {
29-
TextField("", value: $prefs.preferences.textEditing.defaultTabWidth, formatter: numberFormat)
42+
TextField("", value: $prefs.preferences.textEditing.defaultTabWidth, formatter: tabWidthFormatter)
3043
.multilineTextAlignment(.trailing)
3144
.frame(width: 40)
3245
Stepper("Default Tab Width:",
@@ -38,6 +51,9 @@ struct TextEditingPreferencesView: View {
3851
PreferencesSection("Font") {
3952
fontSelector
4053
}
54+
PreferencesSection("Line Height") {
55+
lineHeight
56+
}
4157
PreferencesSection("Code completion") {
4258
autocompleteBraces
4359
enableTypeOverCompletion
@@ -86,4 +102,15 @@ struct TextEditingPreferencesView: View {
86102
}
87103
}
88104

105+
private var lineHeight: some View {
106+
HStack(spacing: 5) {
107+
TextField("", value: $prefs.preferences.textEditing.lineHeightMultiple, formatter: lineHeightFormatter)
108+
.multilineTextAlignment(.trailing)
109+
.frame(width: 40)
110+
Stepper("Line Height:",
111+
value: $prefs.preferences.textEditing.lineHeightMultiple,
112+
in: 0.75...2.0,
113+
step: 0.05)
114+
}
115+
}
89116
}

CodeEdit/Features/CodeFile/CodeFileView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct CodeFileView: View {
6969
theme: $selectedTheme.editor.editorTheme,
7070
font: $font,
7171
tabWidth: $prefs.preferences.textEditing.defaultTabWidth,
72-
lineHeight: .constant(1.2), // TODO: Add to preferences
72+
lineHeight: $prefs.preferences.textEditing.lineHeightMultiple,
7373
wrapLines: $prefs.preferences.textEditing.wrapLinesToEditorWidth,
7474
cursorPosition: codeFile.$cursorPosition
7575
)

0 commit comments

Comments
 (0)