File tree 2 files changed +20
-0
lines changed
Sources/RichEditorSwiftUI
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 {
150
150
}
151
151
152
152
open func textViewDidChangeSelection( _ notification: Notification ) {
153
+ replaceCurrentAttributesIfNeeded ( )
153
154
context. onTextViewEvent (
154
155
. didChangeSelection(
155
156
selectedRange: textView. selectedRange,
@@ -272,6 +273,19 @@ extension RichTextCoordinator {
272
273
if textView. hasSelectedRange { return }
273
274
let attributes = textView. richTextAttributes
274
275
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)
275
289
#endif
276
290
}
277
291
}
Original file line number Diff line number Diff line change @@ -51,5 +51,11 @@ public extension RichTextViewComponent {
51
51
setRichTextAttribute ( attribute, to: value)
52
52
}
53
53
}
54
+
55
+ func setNewRichTextAttributes(
56
+ _ attributes: RichTextAttributes
57
+ ) {
58
+ typingAttributes = attributes
59
+ }
54
60
}
55
61
You can’t perform that action at this time.
0 commit comments