aboutsummaryrefslogtreecommitdiff
path: root/Map
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2025-07-09 08:54:22 +0200
committerRuben Beltran del Rio <git@r.bdr.sh>2025-07-09 08:54:22 +0200
commit005c2048af141e3658a170c283dd41bd4fb5cdcb (patch)
tree9a07100197681a38a78e663c66d034bfacf6ec71 /Map
parent1e89ea22d551cebfd6c0c0451000c3283ddb2d2e (diff)
Make soft-wrap configurable.
Diffstat (limited to 'Map')
-rw-r--r--Map/Data/UserPreferences.swift11
-rw-r--r--Map/Localizable.xcstrings10
-rw-r--r--Map/Presentation/Base Components/MapTextEditor.swift16
-rw-r--r--Map/Presentation/MapEditor.swift4
-rw-r--r--Map/Presentation/Preferences/EditorPreferencesView.swift9
5 files changed, 45 insertions, 5 deletions
diff --git a/Map/Data/UserPreferences.swift b/Map/Data/UserPreferences.swift
index cf9dd7e..12f83c5 100644
--- a/Map/Data/UserPreferences.swift
+++ b/Map/Data/UserPreferences.swift
@@ -29,6 +29,7 @@ struct UserPreferencesJSON: Codable {
var useCustomEditorFont: Bool?
var customEditorFontName: String?
var editorFontSize: Double?
+ var softWrapLines: Bool?
// MARK: - Templates (as actual objects)
var mapTemplates: [Template]?
@@ -55,6 +56,7 @@ struct UserPreferences: Codable {
var useCustomEditorFont: Bool
var customEditorFontName: String
var editorFontSize: Double
+ var softWrapLines: Bool
// MARK: - Templates
var mapTemplates: Data
@@ -78,6 +80,7 @@ struct UserPreferences: Codable {
static let useCustomEditorFont = false
static let customEditorFontName = "Menlo"
static let editorFontSize = 14.0
+ static let softWrapLines = false
static let viewStyle = "horizontal"
static let zoom = 1.0
@@ -119,6 +122,7 @@ struct UserPreferences: Codable {
self.useCustomEditorFont = Defaults.useCustomEditorFont
self.customEditorFontName = Defaults.customEditorFontName
self.editorFontSize = Defaults.editorFontSize
+ self.softWrapLines = Defaults.softWrapLines
self.mapTemplates = Defaults.mapTemplates
self.customStages = Defaults.customStages
@@ -144,6 +148,7 @@ struct UserPreferences: Codable {
useCustomEditorFont: useCustomEditorFont,
customEditorFontName: customEditorFontName,
editorFontSize: editorFontSize,
+ softWrapLines: softWrapLines,
mapTemplates: templatesFromData(mapTemplates),
customStages: stagesFromData(customStages),
viewStyle: viewStyle,
@@ -192,6 +197,9 @@ struct UserPreferences: Codable {
if let value = jsonPrefs.editorFontSize {
self.editorFontSize = value
}
+ if let value = jsonPrefs.softWrapLines {
+ self.softWrapLines = value
+ }
if let value = jsonPrefs.mapTemplates {
self.mapTemplates = dataFromTemplates(value)
}
@@ -264,6 +272,7 @@ struct UserPreferences: Codable {
defaults.set(useCustomEditorFont, forKey: "useCustomEditorFont")
defaults.set(customEditorFontName, forKey: "customEditorFontName")
defaults.set(editorFontSize, forKey: "editorFontSize")
+ defaults.set(softWrapLines, forKey: "softWrapLines")
// Templates
defaults.set(mapTemplates, forKey: "mapTemplates")
@@ -304,6 +313,8 @@ struct UserPreferences: Codable {
defaults.object(forKey: "customEditorFontName") as? String ?? Defaults.customEditorFontName
preferences.editorFontSize =
defaults.object(forKey: "editorFontSize") as? Double ?? Defaults.editorFontSize
+ preferences.softWrapLines =
+ defaults.object(forKey: "softWrapLines") as? Bool ?? Defaults.softWrapLines
// Templates
preferences.mapTemplates =
diff --git a/Map/Localizable.xcstrings b/Map/Localizable.xcstrings
index 8f9ddce..d5da2e4 100644
--- a/Map/Localizable.xcstrings
+++ b/Map/Localizable.xcstrings
@@ -318,6 +318,16 @@
}
}
},
+ "preferences.editor.editor_style.soft_wrap_lines" : {
+ "localizations" : {
+ "en" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Soft wrap long lines"
+ }
+ }
+ }
+ },
"preferences.editor.editor_style.title" : {
"extractionState" : "manual",
"localizations" : {
diff --git a/Map/Presentation/Base Components/MapTextEditor.swift b/Map/Presentation/Base Components/MapTextEditor.swift
index c4ac561..4295918 100644
--- a/Map/Presentation/Base Components/MapTextEditor.swift
+++ b/Map/Presentation/Base Components/MapTextEditor.swift
@@ -82,12 +82,20 @@ class MapTextEditorController: NSViewController {
textView.font = NSFont.Theme.Editor.regular
textView.textContainerInset = NSSize(width: 0, height: Dimensions.Spacing.coziest)
- // Disable word wrapping to prevent flashing on soft-wrapped lines
- textView.textContainer?.widthTracksTextView = false
- textView.textContainer?.containerSize = NSSize(
- width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)
+ // Configure text wrapping based on user preference
+ let softWrapLines = UserDefaults.standard.bool(forKey: "softWrapLines")
+ if !softWrapLines {
+ // Disable word wrapping to prevent flashing on soft-wrapped lines
+ textView.textContainer?.widthTracksTextView = false
+ textView.textContainer?.containerSize = NSSize(
+ width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)
+ } else {
+ textView.textContainer?.widthTracksTextView = true
+ }
+
textView.isHorizontallyResizable = true
textView.isVerticallyResizable = true
+
self.view = scrollView
}
diff --git a/Map/Presentation/MapEditor.swift b/Map/Presentation/MapEditor.swift
index 0f8f24e..c8ce5cd 100644
--- a/Map/Presentation/MapEditor.swift
+++ b/Map/Presentation/MapEditor.swift
@@ -32,6 +32,8 @@ struct MapEditor: View {
@AppStorage("customEditorFontName") var customEditorFontName: String = UserPreferences.Defaults
.customEditorFontName
@AppStorage("editorFontSize") var editorFontSize: Double = UserPreferences.Defaults.editorFontSize
+ @AppStorage("softWrapLines") var softWrapLines: Bool = UserPreferences.Defaults
+ .softWrapLines
let zoomRange = Constants.kMinZoom...Constants.kMaxZoom
@AppStorage("zoom") var zoom = UserPreferences.Defaults.zoom
@@ -110,7 +112,7 @@ struct MapEditor: View {
highlightRanges: results,
selectedRange: selectedTerm
)
- .id("\(useCustomEditorFont)-\(customEditorFontName)-\(editorFontSize)")
+ .id("\(useCustomEditorFont)-\(customEditorFontName)-\(editorFontSize)-\(softWrapLines)")
.background(Color.Theme.UI.background)
.foregroundColor(Color.Theme.UI.foreground)
.frame(minHeight: 96.0)
diff --git a/Map/Presentation/Preferences/EditorPreferencesView.swift b/Map/Presentation/Preferences/EditorPreferencesView.swift
index 23359b2..c08b03e 100644
--- a/Map/Presentation/Preferences/EditorPreferencesView.swift
+++ b/Map/Presentation/Preferences/EditorPreferencesView.swift
@@ -24,6 +24,8 @@ struct EditorPreferencesView: View {
.customEditorFontName
@AppStorage("editorFontSize") private var editorFontSize: Double = UserPreferences.Defaults
.editorFontSize
+ @AppStorage("softWrapLines") private var softWrapLines: Bool = UserPreferences.Defaults
+ .softWrapLines
var monospacedFonts: [String] {
let fontManager = NSFontManager.shared
@@ -79,6 +81,13 @@ struct EditorPreferencesView: View {
VStack(alignment: .leading, spacing: Dimensions.Spacing.cozy) {
Toggle(
+ isOn: $softWrapLines,
+ label: {
+ Text("preferences.editor.editor_style.soft_wrap_lines")
+ .font(.Theme.Body.regular)
+ })
+
+ Toggle(
isOn: $useCustomEditorFont,
label: {
Text("preferences.editor.editor_style.use_custom_font")