File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
Sources/RichEditorSwiftUI Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,7 @@ open class RichTextCoordinator: NSObject {
150150 }
151151
152152 open func textViewDidChangeSelection( _ notification: Notification ) {
153+ replaceCurrentAttributesIfNeeded ( )
153154 context. onTextViewEvent (
154155 . didChangeSelection(
155156 selectedRange: textView. selectedRange,
@@ -272,6 +273,19 @@ extension RichTextCoordinator {
272273 if textView. hasSelectedRange { return }
273274 let attributes = textView. richTextAttributes
274275 textView. setRichTextAttributes ( attributes)
276+ #endif
277+ }
278+
279+ /**
280+ On macOS, we have to update the typingAttributes when we
281+ move the text input cursor and there's no selected text.
282+ So that the current attributes will set again for updated location.
283+ */
284+ func replaceCurrentAttributesIfNeeded( ) {
285+ #if macOS
286+ if textView. hasSelectedRange { return }
287+ let attributes = textView. richTextAttributes
288+ textView. setNewRichTextAttributes ( attributes)
275289#endif
276290 }
277291}
Original file line number Diff line number Diff line change @@ -51,5 +51,11 @@ public extension RichTextViewComponent {
5151 setRichTextAttribute ( attribute, to: value)
5252 }
5353 }
54+
55+ func setNewRichTextAttributes(
56+ _ attributes: RichTextAttributes
57+ ) {
58+ typingAttributes = attributes
59+ }
5460}
5561
You can’t perform that action at this time.
0 commit comments