@@ -153,6 +153,12 @@ open class EditorView: UIView {
153
153
/// Context for the current Editor
154
154
public let editorViewContext : EditorViewContext
155
155
156
+ /// Returns if `attributedText` change is pending. `AttributedText` may not have been applied if the `EditorView` is not already on
157
+ /// `window` and `forceApplyAttributedText` is not set to `true`.
158
+ public var isAttributedTextPending : Bool {
159
+ pendingAttributedText != nil
160
+ }
161
+
156
162
/// Enables asynchronous rendering of attachments.
157
163
/// - Note:
158
164
/// Since attachments must me rendered on main thread, the rendering only continues when there is no user interaction. By default, rendering starts
@@ -341,6 +347,7 @@ open class EditorView: UIView {
341
347
/// An attachment is only counted as a single character. Content length does not include
342
348
/// length of content within the Attachment that is hosting another `EditorView`.
343
349
public var contentLength : Int {
350
+ guard pendingAttributedText == nil else { return attributedText. length }
344
351
return richTextView. contentLength
345
352
}
346
353
@@ -461,6 +468,11 @@ open class EditorView: UIView {
461
468
public var forceApplyAttributedText = false
462
469
463
470
/// Text to be set in the `EditorView`
471
+ /// - Important: `attributedText` is not set for rendering in `EditorView` if the `EditorView` is not already in a `Window`. Value of `true`
472
+ /// for `isAttributedTextPending` confirms that the text has not yet been rendered even though it is set in the `EditorView`.
473
+ /// Notification of text being set can be observed by subscribing to `didSetAttributedText` in `EditorViewDelegate`.
474
+ /// Alternatively, `forceApplyAttributedText` may be set to `true` to always apply `attributedText` irrespective of `EditorView` being
475
+ /// in a `Window` or not.
464
476
public var attributedText : NSAttributedString {
465
477
get {
466
478
pendingAttributedText ?? richTextView. attributedText
@@ -787,7 +799,7 @@ open class EditorView: UIView {
787
799
}
788
800
789
801
public func attachmentsInRange( _ range: NSRange ) -> [ AttachmentRange ] {
790
- guard range. endLocation < contentLength else { return [ ] }
802
+ guard range. endLocation < attributedText . length else { return [ ] }
791
803
let substring = attributedText. attributedSubstring ( from: range)
792
804
return substring. attachmentRanges
793
805
}
0 commit comments