-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow customizing soft break mode (#342)
* Allow customizing soft break mode Resolved #341 * Attributed renderer * Tests * Update snapshots
- Loading branch information
Showing
8 changed files
with
104 additions
and
5 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
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 `lineBreak`, 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 markdownSoftBreakMode(_ 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
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
Binary file added
BIN
+60.4 KB
Tests/MarkdownUITests/__Snapshots__/MarkdownTests/testSoftBreakModeLineBreak.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+55.9 KB
Tests/MarkdownUITests/__Snapshots__/MarkdownTests/testSoftBreakModeSpace.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.