forked from facebookarchive/AsyncDisplayKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASEditableTextNode.mm
More file actions
558 lines (446 loc) · 21.7 KB
/
ASEditableTextNode.mm
File metadata and controls
558 lines (446 loc) · 21.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
/* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "ASEditableTextNode.h"
#import <objc/message.h>
#import "ASDisplayNode+Subclasses.h"
#import "ASEqualityHelpers.h"
#import "ASTextNodeTextKitHelpers.h"
#import "ASTextNodeWordKerner.h"
#import "ASThread.h"
//! @abstract This subclass exists solely to ensure the text view's panGestureRecognizer never begins, because it's sporadically enabled by UITextView. It will be removed pending rdar://14729288.
@interface _ASDisabledPanUITextView : UITextView
@end
@implementation _ASDisabledPanUITextView
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
// Never allow our pans to begin.
if (gestureRecognizer == self.panGestureRecognizer)
return NO;
// Otherwise, proceed as usual.
if ([UITextView instancesRespondToSelector:_cmd])
return [super gestureRecognizerShouldBegin:gestureRecognizer];
return YES;
}
@end
#pragma mark -
@interface ASEditableTextNode () <UITextViewDelegate, NSLayoutManagerDelegate>
{
@private
// Configuration.
NSDictionary *_typingAttributes;
// Core.
id <ASEditableTextNodeDelegate> __weak _delegate;
BOOL _delegateDidUpdateEnqueued;
// TextKit.
ASDN::RecursiveMutex _textKitLock;
ASTextKitComponents *_textKitComponents;
ASTextKitComponents *_placeholderTextKitComponents;
// Forwards NSLayoutManagerDelegate methods related to word kerning
ASTextNodeWordKerner *_wordKerner;
// Misc. State.
BOOL _displayingPlaceholder; // Defaults to YES.
BOOL _isPreservingSelection;
BOOL _selectionChangedForEditedText;
NSRange _previousSelectedRange;
}
@end
@implementation ASEditableTextNode
#pragma mark - NSObject Overrides
- (instancetype)init
{
if (!(self = [super init]))
return nil;
_displayingPlaceholder = YES;
// Create the scaffolding for the text view.
_textKitComponents = [ASTextKitComponents componentsWithAttributedSeedString:nil textContainerSize:CGSizeZero];
_textKitComponents.layoutManager.delegate = self;
_wordKerner = [[ASTextNodeWordKerner alloc] init];
_returnKeyType = UIReturnKeyDefault;
_textContainerInset = UIEdgeInsetsZero;
// Create the placeholder scaffolding.
_placeholderTextKitComponents = [ASTextKitComponents componentsWithAttributedSeedString:nil textContainerSize:CGSizeZero];
_placeholderTextKitComponents.layoutManager.delegate = self;
return self;
}
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
{
ASDisplayNodeAssertNotSupported();
return nil;
}
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
{
ASDisplayNodeAssertNotSupported();
return nil;
}
- (void)dealloc
{
_textKitComponents.textView.delegate = nil;
_textKitComponents.layoutManager.delegate = nil;
_placeholderTextKitComponents.layoutManager.delegate = nil;
}
#pragma mark - ASDisplayNode Overrides
- (void)didLoad
{
[super didLoad];
ASDN::MutexLocker l(_textKitLock);
void (^configureTextView)(UITextView *) = ^(UITextView *textView) {
if (!_displayingPlaceholder || textView != _textKitComponents.textView) {
// If showing the placeholder, don't propagate backgroundColor/opaque to the editable textView. It is positioned over the placeholder to accept taps to begin editing, and if it's opaque/colored then it'll obscure the placeholder.
textView.backgroundColor = self.backgroundColor;
textView.opaque = self.opaque;
} else if (_displayingPlaceholder && textView == _textKitComponents.textView) {
// The default backgroundColor for a textView is white. Due to the reason described above, make sure the editable textView starts out transparent.
textView.backgroundColor = nil;
textView.opaque = NO;
}
textView.textContainerInset = self.textContainerInset;
textView.clipsToBounds = NO; // We don't want selection handles cut off.
};
// Create and configure the placeholder text view.
_placeholderTextKitComponents.textView = [[UITextView alloc] initWithFrame:CGRectZero textContainer:_placeholderTextKitComponents.textContainer];
_placeholderTextKitComponents.textView.userInteractionEnabled = NO;
_placeholderTextKitComponents.textView.accessibilityElementsHidden = YES;
configureTextView(_placeholderTextKitComponents.textView);
[self.view addSubview:_placeholderTextKitComponents.textView];
// Create and configure our text view.
_textKitComponents.textView = self.textView;
//_textKitComponents.textView = NO; // Unfortunately there's a bug here with iOS 7 DP5 that causes the text-view to only be one line high when scrollEnabled is NO. rdar://14729288
_textKitComponents.textView.delegate = self;
_textKitComponents.textView.editable = YES;
_textKitComponents.textView.typingAttributes = _typingAttributes;
_textKitComponents.textView.returnKeyType = _returnKeyType;
_textKitComponents.textView.accessibilityHint = _placeholderTextKitComponents.textStorage.string;
configureTextView(_textKitComponents.textView);
[self.view addSubview:_textKitComponents.textView];
[self _updateDisplayingPlaceholder];
}
- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
{
ASTextKitComponents *displayedComponents = [self isDisplayingPlaceholder] ? _placeholderTextKitComponents : _textKitComponents;
CGSize textSize = [displayedComponents sizeForConstrainedWidth:constrainedSize.width];
textSize = ceilSizeValue(textSize);
return CGSizeMake(constrainedSize.width, fminf(textSize.height, constrainedSize.height));
}
- (void)layout
{
ASDisplayNodeAssertMainThread();
[self _layoutTextView];
}
- (void)setBackgroundColor:(UIColor *)backgroundColor
{
[super setBackgroundColor:backgroundColor];
ASDN::MutexLocker l(_textKitLock);
// If showing the placeholder, don't propagate backgroundColor/opaque to the editable textView. It is positioned over the placeholder to accept taps to begin editing, and if it's opaque/colored then it'll obscure the placeholder.
// The backgroundColor/opaque will be propagated to the editable textView when editing begins.
if (!_displayingPlaceholder) {
_textKitComponents.textView.backgroundColor = backgroundColor;
}
_placeholderTextKitComponents.textView.backgroundColor = backgroundColor;
}
- (void)setTextContainerInset:(UIEdgeInsets)textContainerInset
{
ASDN::MutexLocker l(_textKitLock);
_textContainerInset = textContainerInset;
_textKitComponents.textView.textContainerInset = textContainerInset;
_placeholderTextKitComponents.textView.textContainerInset = textContainerInset;
}
- (void)setOpaque:(BOOL)opaque
{
[super setOpaque:opaque];
ASDN::MutexLocker l(_textKitLock);
// If showing the placeholder, don't propagate backgroundColor/opaque to the editable textView. It is positioned over the placeholder to accept taps to begin editing, and if it's opaque/colored then it'll obscure the placeholder.
// The backgroundColor/opaque will be propagated to the editable textView when editing begins.
if (!_displayingPlaceholder) {
_textKitComponents.textView.opaque = opaque;
}
_placeholderTextKitComponents.textView.opaque = opaque;
}
- (void)setLayerBacked:(BOOL)layerBacked
{
ASDisplayNodeAssert(!layerBacked, @"Cannot set layerBacked to YES on ASEditableTextNode – instances must be view-backed in order to ensure touch events can be passed to the internal UITextView during editing.");
[super setLayerBacked:layerBacked];
}
#pragma mark - Configuration
@synthesize delegate = _delegate;
- (UITextView *)textView
{
ASDisplayNodeAssertMainThread();
if (!_textKitComponents.textView) {
_textKitComponents.textView = [[_ASDisabledPanUITextView alloc] initWithFrame:CGRectZero textContainer:_textKitComponents.textContainer];
}
return _textKitComponents.textView;
}
#pragma mark -
@dynamic typingAttributes;
- (NSDictionary *)typingAttributes
{
return _typingAttributes;
}
- (void)setTypingAttributes:(NSDictionary *)typingAttributes
{
if (ASObjectIsEqual(typingAttributes, _typingAttributes))
return;
_typingAttributes = [typingAttributes copy];
ASDN::MutexLocker l(_textKitLock);
_textKitComponents.textView.typingAttributes = _typingAttributes;
}
#pragma mark -
@dynamic selectedRange;
- (NSRange)selectedRange
{
ASDN::MutexLocker l(_textKitLock);
return _textKitComponents.textView.selectedRange;
}
- (void)setSelectedRange:(NSRange)selectedRange
{
ASDN::MutexLocker l(_textKitLock);
_textKitComponents.textView.selectedRange = selectedRange;
}
#pragma mark - Placeholder
- (BOOL)isDisplayingPlaceholder
{
return _displayingPlaceholder;
}
#pragma mark -
@dynamic attributedPlaceholderText;
- (NSAttributedString *)attributedPlaceholderText
{
ASDN::MutexLocker l(_textKitLock);
return [_placeholderTextKitComponents.textStorage copy];
}
- (void)setAttributedPlaceholderText:(NSAttributedString *)attributedPlaceholderText
{
ASDN::MutexLocker l(_textKitLock);
if (ASObjectIsEqual(_placeholderTextKitComponents.textStorage, attributedPlaceholderText))
return;
[_placeholderTextKitComponents.textStorage setAttributedString:attributedPlaceholderText ?: [[NSAttributedString alloc] initWithString:@""]];
_textKitComponents.textView.accessibilityHint = attributedPlaceholderText.string;
}
#pragma mark - Modifying User Text
@dynamic attributedText;
- (NSAttributedString *)attributedText
{
// Per contract in our header, this value is nil when the placeholder is displayed.
if ([self isDisplayingPlaceholder])
return nil;
ASDN::MutexLocker l(_textKitLock);
return [_textKitComponents.textStorage copy];
}
- (void)setAttributedText:(NSAttributedString *)attributedText
{
ASDN::MutexLocker l(_textKitLock);
// If we (_cmd) are called while the text view itself is updating (-textViewDidUpdate:), you cannot update the text storage and expect perfect propagation to the text view.
// Thus, we always update the textview directly if it's been created already.
if (ASObjectIsEqual((_textKitComponents.textView.attributedText ?: _textKitComponents.textStorage), attributedText))
return;
// If the cursor isn't at the end of the text, we need to preserve the selected range to avoid moving the cursor.
NSRange selectedRange = _textKitComponents.textView.selectedRange;
BOOL preserveSelectedRange = (selectedRange.location != _textKitComponents.textStorage.length);
NSAttributedString *attributedStringToDisplay = nil;
if (attributedText)
attributedStringToDisplay = attributedText;
// Otherwise, note that we don't simply nil out attributed text. Because the insertion point is guided by the attributes at index 0, we need to attribute an empty string to ensure the insert point obeys our typing attributes.
else
attributedStringToDisplay = [[NSAttributedString alloc] initWithString:@"" attributes:self.typingAttributes];
// Always prefer updating the text view directly if it's been created (see above).
if (_textKitComponents.textView)
[_textKitComponents.textView setAttributedText:attributedStringToDisplay];
else
[_textKitComponents.textStorage setAttributedString:attributedStringToDisplay];
// Calculated size depends on the seeded text.
[self invalidateCalculatedLayout];
// Update if placeholder is shown.
[self _updateDisplayingPlaceholder];
// Preserve cursor range, if necessary.
if (preserveSelectedRange) {
_isPreservingSelection = YES; // Used in -textViewDidChangeSelection: to avoid informing our delegate about our preservation.
[_textKitComponents.textView setSelectedRange:selectedRange];
_isPreservingSelection = NO;
}
}
#pragma mark - Core
- (void)_updateDisplayingPlaceholder
{
ASDN::MutexLocker l(_textKitLock);
// Show the placeholder if necessary.
_displayingPlaceholder = (_textKitComponents.textStorage.length == 0);
_placeholderTextKitComponents.textView.hidden = !_displayingPlaceholder;
// If hiding the placeholder, propagate backgroundColor/opaque to the editable textView. It is positioned over the placeholder to accept taps to begin editing, and was kept transparent so it doesn't obscure the placeholder text. Now that we're editing it and the placeholder is hidden, we can make it opaque to avoid unnecessary blending.
if (!_displayingPlaceholder) {
_textKitComponents.textView.opaque = self.isOpaque;
_textKitComponents.textView.backgroundColor = self.backgroundColor;
} else {
_textKitComponents.textView.opaque = NO;
_textKitComponents.textView.backgroundColor = nil;
}
}
- (void)_layoutTextView
{
ASDN::MutexLocker l(_textKitLock);
// Layout filling our bounds.
_textKitComponents.textView.frame = self.bounds;
_placeholderTextKitComponents.textView.frame = self.bounds;
// Note that both of these won't be necessary once we can disable scrolling, pending rdar://14729288
// When we resize to fit (above) the prior layout becomes invalid. For whatever reason, UITextView doesn't invalidate its layout when its frame changes on its own, so we have to do so ourselves.
[_textKitComponents.layoutManager invalidateLayoutForCharacterRange:NSMakeRange(0, [_textKitComponents.textStorage length]) actualCharacterRange:NULL];
// When you type beyond UITextView's bounds it scrolls you down a line. We need to remain at the top.
[_textKitComponents.textView setContentOffset:CGPointZero animated:NO];
}
#pragma mark - Keyboard
@dynamic textInputMode;
- (UITextInputMode *)textInputMode
{
ASDN::MutexLocker l(_textKitLock);
return [_textKitComponents.textView textInputMode];
}
- (void)setReturnKeyType:(UIReturnKeyType)returnKeyType
{
ASDN::MutexLocker l(_textKitLock);
_returnKeyType = returnKeyType;
[_textKitComponents.textView setReturnKeyType:_returnKeyType];
}
- (BOOL)isFirstResponder
{
ASDN::MutexLocker l(_textKitLock);
return [_textKitComponents.textView isFirstResponder];
}
- (BOOL)canBecomeFirstResponder {
ASDN::MutexLocker l(_textKitLock);
return [_textKitComponents.textView canBecomeFirstResponder];
}
- (BOOL)becomeFirstResponder
{
ASDN::MutexLocker l(_textKitLock);
return [_textKitComponents.textView becomeFirstResponder];
}
- (BOOL)canResignFirstResponder {
ASDN::MutexLocker l(_textKitLock);
return [_textKitComponents.textView canResignFirstResponder];
}
- (BOOL)resignFirstResponder
{
ASDN::MutexLocker l(_textKitLock);
return [_textKitComponents.textView resignFirstResponder];
}
#pragma mark - UITextView Delegate
- (void)textViewDidBeginEditing:(UITextView *)textView
{
// Delegateify.
[self _delegateDidBeginEditing];
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
// Delegateify.
return [self _delegateShouldChangeTextInRange:range replacementText:text];
}
- (void)textViewDidChange:(UITextView *)textView
{
ASDN::MutexLocker l(_textKitLock);
// Note we received a text changed event.
// This is used by _delegateDidChangeSelectionFromSelectedRange:toSelectedRange: to distinguish between selection changes that happen because of editing or pure selection changes.
_selectionChangedForEditedText = YES;
// Update if the placeholder is visible.
[self _updateDisplayingPlaceholder];
// Invalidate, as our calculated size depends on the textview's seeded text.
[self invalidateCalculatedLayout];
// Delegateify.
[self _delegateDidUpdateText];
}
- (void)textViewDidChangeSelection:(UITextView *)textView
{
// Typing attributes get reset when selection changes. Reapply them so they actually obey our header.
_textKitComponents.textView.typingAttributes = _typingAttributes;
// If we're only changing selection to preserve it, don't notify about anything.
if (_isPreservingSelection)
return;
// Note if we receive a -textDidChange: between now and when we delegatify.
// This is used by _delegateDidChangeSelectionFromSelectedRange:toSelectedRange: to distinguish between selection changes that happen because of editing or pure selection changes.
_selectionChangedForEditedText = NO;
NSRange fromSelectedRange = _previousSelectedRange;
NSRange toSelectedRange = self.selectedRange;
_previousSelectedRange = toSelectedRange;
// Delegateify.
[self _delegateDidChangeSelectionFromSelectedRange:fromSelectedRange toSelectedRange:toSelectedRange];
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
// Delegateify.
[self _delegateDidFinishEditing];
}
#pragma mark - NSLayoutManager Delegate
- (NSUInteger)layoutManager:(NSLayoutManager *)layoutManager shouldGenerateGlyphs:(const CGGlyph *)glyphs properties:(const NSGlyphProperty *)properties characterIndexes:(const NSUInteger *)characterIndexes font:(UIFont *)aFont forGlyphRange:(NSRange)glyphRange
{
return [_wordKerner layoutManager:layoutManager shouldGenerateGlyphs:glyphs properties:properties characterIndexes:characterIndexes font:aFont forGlyphRange:glyphRange];
}
- (NSControlCharacterAction)layoutManager:(NSLayoutManager *)layoutManager shouldUseAction:(NSControlCharacterAction)defaultAction forControlCharacterAtIndex:(NSUInteger)characterIndex
{
return [_wordKerner layoutManager:layoutManager shouldUseAction:defaultAction forControlCharacterAtIndex:characterIndex];
}
- (CGRect)layoutManager:(NSLayoutManager *)layoutManager boundingBoxForControlGlyphAtIndex:(NSUInteger)glyphIndex forTextContainer:(NSTextContainer *)textContainer proposedLineFragment:(CGRect)proposedRect glyphPosition:(CGPoint)glyphPosition characterIndex:(NSUInteger)characterIndex
{
return [_wordKerner layoutManager:layoutManager boundingBoxForControlGlyphAtIndex:glyphIndex forTextContainer:textContainer proposedLineFragment:proposedRect glyphPosition:glyphPosition characterIndex:characterIndex];
}
#pragma mark - Geometry
- (CGRect)frameForTextRange:(NSRange)textRange
{
ASDN::MutexLocker l(_textKitLock);
// Bail on invalid range.
if (NSMaxRange(textRange) > [_textKitComponents.textStorage length]) {
ASDisplayNodeAssert(NO, @"Invalid range");
return CGRectZero;
}
// Force glyph generation and layout.
[_textKitComponents.layoutManager ensureLayoutForTextContainer:_textKitComponents.textContainer];
NSRange glyphRange = [_textKitComponents.layoutManager glyphRangeForCharacterRange:textRange actualCharacterRange:NULL];
CGRect textRect = [_textKitComponents.layoutManager boundingRectForGlyphRange:glyphRange inTextContainer:_textKitComponents.textContainer];
return [_textKitComponents.textView convertRect:textRect toView:self.view];
}
#pragma mark -
- (void)_delegateDidBeginEditing
{
if ([_delegate respondsToSelector:@selector(editableTextNodeDidBeginEditing:)])
[_delegate editableTextNodeDidBeginEditing:self];
}
- (BOOL)_delegateShouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if ([_delegate respondsToSelector:@selector(editableTextNode:shouldChangeTextInRange:replacementText:)]) {
return [_delegate editableTextNode:self shouldChangeTextInRange:range replacementText:text];
}
return YES;
}
- (void)_delegateDidChangeSelectionFromSelectedRange:(NSRange)fromSelectedRange toSelectedRange:(NSRange)toSelectedRange
{
// There are two reasons we're invoking the delegate on the next run of the runloop.
// 1. UITextView invokes its delegate methods when it's in the middle of text-processing. For example, -textViewDidChange: is invoked before you can truly rely on the changes being propagated throughout the Text Kit hierarchy.
// 2. This delegate method (-textViewDidChangeSelection:) is called both before -textViewDidChange: and before the layout manager/etc. has necessarily generated+laid out its glyphs. Because of the former, we need to wait until -textViewDidChange: has had an opportunity to be called so can accurately determine whether this selection change is due to editing (_selectionChangedForEditedText).
// Thus, to avoid calling out to client code in the middle of UITextView's processing, we call the delegate on the next run of the runloop, when all such internal processing is surely done.
dispatch_async(dispatch_get_main_queue(), ^{
if ([_delegate respondsToSelector:@selector(editableTextNodeDidChangeSelection:fromSelectedRange:toSelectedRange:dueToEditing:)])
[_delegate editableTextNodeDidChangeSelection:self fromSelectedRange:fromSelectedRange toSelectedRange:toSelectedRange dueToEditing:_selectionChangedForEditedText];
});
}
- (void)_delegateDidUpdateText
{
// Note that because -editableTextNodeDidUpdateText: passes no state, the current state of the receiver will be accessed. Thus, it's not useful to enqueue a second delegation call if the first hasn't happened yet -- doing so will result in the delegate receiving -editableTextNodeDidUpdateText: when the "updated text" has already been processed. This may sound innocuous, but because our delegation may cause additional updates to the textview's string, and because such updates discard spelling suggestions and autocompletions (like double-space to `.`), it can actually be quite dangerous!
if (_delegateDidUpdateEnqueued)
return;
_delegateDidUpdateEnqueued = YES;
// UITextView invokes its delegate methods when it's in the middle of text-processing. For example, -textViewDidChange: is invoked before you can truly rely on the changes being propagated throughout the Text Kit hierarchy.
// Thus, to avoid calling out to client code in the middle of UITextView's processing, we call the delegate on the next run of the runloop, when all such internal processing is surely done.
dispatch_async(dispatch_get_main_queue(), ^{
_delegateDidUpdateEnqueued = NO;
if ([_delegate respondsToSelector:@selector(editableTextNodeDidUpdateText:)])
[_delegate editableTextNodeDidUpdateText:self];
});
}
- (void)_delegateDidFinishEditing
{
if ([_delegate respondsToSelector:@selector(editableTextNodeDidFinishEditing:)])
[_delegate editableTextNodeDidFinishEditing:self];
}
@end