-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix styles are added and removed on selecting text
- Loading branch information
1 parent
83c5e2a
commit fa396f6
Showing
8 changed files
with
112 additions
and
17 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
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
34 changes: 34 additions & 0 deletions
34
Sources/RichEditorSwiftUI/UI/Context/RichEditorState+Header.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,34 @@ | ||
// | ||
// RichEditorState+Header.swift | ||
// RichEditorSwiftUI | ||
// | ||
// Created by Divyesh Vekariya on 29/11/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public extension RichEditorState { | ||
|
||
/// Get a binding for a certain style. | ||
func headerBinding() -> Binding<HeaderType> { | ||
Binding( | ||
get: { self.currentHeader() }, | ||
set: { self.setHeaderStyle($0) } | ||
) | ||
} | ||
|
||
/// Check whether or not the context has a certain header style. | ||
func currentHeader() -> HeaderType { | ||
return headerType | ||
} | ||
|
||
/// Set whether or not the context has a certain header style. | ||
func setHeaderStyle( | ||
_ header: HeaderType | ||
) { | ||
guard header != headerType else { return } | ||
updateStyle(style: header.getTextSpanStyle()) | ||
} | ||
|
||
} | ||
|
42 changes: 42 additions & 0 deletions
42
Sources/RichEditorSwiftUI/UI/TextViewUI/RichEditorStateFocusedValueKey.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,42 @@ | ||
// | ||
// RichEditorStateFocusedValueKey.swift | ||
// RichEditorSwiftUI | ||
// | ||
// Created by Divyesh Vekariya on 25/11/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public extension RichEditorState { | ||
|
||
/// This key can be used to keep track of a context in a | ||
/// multi-windowed app. | ||
struct FocusedValueKey: SwiftUI.FocusedValueKey { | ||
|
||
public typealias Value = RichEditorState | ||
} | ||
} | ||
|
||
public extension FocusedValues { | ||
|
||
/// This value can be used to keep track of a context in | ||
/// a multi-windowed app. | ||
/// | ||
/// You can bind a context to a view with `focusedValue`: | ||
/// | ||
/// ```swift | ||
/// RichTextEditor(...) | ||
/// .focusedValue(\.richTextContext, richTextContext) | ||
/// ``` | ||
/// | ||
/// You can then access the context as a `@FocusedValue`: | ||
/// | ||
/// ```swift | ||
/// @FocusedValue(\.richEditorState) | ||
/// var richEditorState: RichEditorState? | ||
/// ``` | ||
var richEditorState: RichEditorState.FocusedValueKey.Value? { | ||
get { self[RichEditorState.FocusedValueKey.self] } | ||
set { self[RichEditorState.FocusedValueKey.self] = newValue } | ||
} | ||
} |