Macos 键入期间NSTextView延迟
我有两个带有共享自定义NSTextStorage子类的NSTEXTVIEW。文本视图相互镜像内容。在我按enter键之前,这一切正常。然后第二个文本视图开始滞后,甚至不显示任何新输入。无论我输入哪个文本视图,都会发生这种情况 如何强制第二个textview与第一个textview保持同步 这是我的NSTextStorage子类Macos 键入期间NSTextView延迟,macos,nstextview,nslayoutmanager,nstextstorage,Macos,Nstextview,Nslayoutmanager,Nstextstorage,我有两个带有共享自定义NSTextStorage子类的NSTEXTVIEW。文本视图相互镜像内容。在我按enter键之前,这一切正常。然后第二个文本视图开始滞后,甚至不显示任何新输入。无论我输入哪个文本视图,都会发生这种情况 如何强制第二个textview与第一个textview保持同步 这是我的NSTextStorage子类 @implementation MyTextStorage { NSTextStorage *_backingStore; } -(id) init {
@implementation MyTextStorage
{
NSTextStorage *_backingStore;
}
-(id) init
{
self = [super init];
if (self)
{
_backingStore = [[NSTextStorage alloc] initWithString:@""];
}
return self;
}
-(NSString *) string
{
return [_backingStore string];
}
-(NSDictionary *) attributesAtIndex:(NSUInteger) location
effectiveRange:(NSRangePointer) range
{
NSMutableDictionary *attributes = [[_backingStore attributesAtIndex:location
effectiveRange:range] mutableCopy];
if ([self displayMode] == MyTextStorageDisplayNormal)
{
[attributes setObject:[NSColor blackColor]
forKey:NSForegroundColorAttributeName];//remove syntax coloring
}
return attributes;
}
#pragma mark - editing
-(void) replaceCharactersInRange:(NSRange)range
withString:(NSString *)string
{
[_backingStore replaceCharactersInRange:range
withString:string];
[self edited:NSTextStorageEditedCharacters
range:range
changeInLength:[string length] - range.length];
}
-(void) setAttributes:(NSDictionary *) attributes
range:(NSRange) range
{
[_backingStore setAttributes:attributes
range:range];
[self edited:NSTextStorageEditedAttributes
range:range
changeInLength:0];
}