-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolved #341
- Loading branch information
Showing
4 changed files
with
50 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
Sources/MarkdownUI/Views/Environment/Environment+SoftBreakMode.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import SwiftUI | ||
|
||
extension View { | ||
/// Sets the soft break mode for inline texts in a view hierarchy. | ||
/// | ||
/// - parameter softBreakMode: If set to `space`, treats all soft breaks as spaces, keeping sentences whole. If set to `newLine`, treats soft breaks as full line breaks | ||
/// | ||
/// - Returns: A view that uses the specified soft break mode for itself and its child views. | ||
public func softBreakMode(_ softBreakMode: SoftBreak.Mode) -> some View { | ||
self.environment(\.softBreakMode, softBreakMode) | ||
} | ||
} | ||
|
||
extension EnvironmentValues { | ||
var softBreakMode: SoftBreak.Mode { | ||
get { self[SoftBreakModeKey.self] } | ||
set { self[SoftBreakModeKey.self] = newValue } | ||
} | ||
} | ||
|
||
private struct SoftBreakModeKey: EnvironmentKey { | ||
static let defaultValue: SoftBreak.Mode = .space | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters