mirror of
https://github.com/zakk4223/CocoaSplit.git
synced 2026-05-15 14:15:50 -06:00
File input always creates attributed text even if the file is plain text. Stops File input from clearing attributed text and then setting plain text, which caused double layer updates per cycle, one with a blank/nil value
This commit is contained in:
parent
e380430968
commit
db39e676f3
8 changed files with 45 additions and 26 deletions
|
|
@ -116,6 +116,7 @@
|
|||
|
||||
-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
|
||||
{
|
||||
|
||||
[self.webView setValue:@NO forKey:@"drawsBackground"];
|
||||
NSString *captureName = self.webView.title;
|
||||
if (!captureName || captureName.length == 0)
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@
|
|||
{
|
||||
if (self = [super init])
|
||||
{
|
||||
self.lineLimit = 0;
|
||||
self.startLine = 0;
|
||||
self.collapseLines = NO;
|
||||
self.fontSizeAdjust = 0;
|
||||
_lineLimit = 0;
|
||||
_startLine = 0;
|
||||
_collapseLines = NO;
|
||||
_fontSizeAdjust = 0;
|
||||
_fileChangeQueue = dispatch_queue_create("File Watch Queue", DISPATCH_QUEUE_SERIAL);
|
||||
}
|
||||
|
||||
|
|
@ -114,8 +114,9 @@
|
|||
|
||||
-(void)setCurrentFile:(NSString *)currentFile
|
||||
{
|
||||
[self openFile:currentFile];
|
||||
_currentFile = currentFile;
|
||||
[self openFile:self.currentFile];
|
||||
|
||||
}
|
||||
|
||||
-(NSString *)currentFile
|
||||
|
|
@ -133,13 +134,19 @@
|
|||
{
|
||||
|
||||
|
||||
if (!self.currentFile)
|
||||
|
||||
if (!filename)
|
||||
{
|
||||
[self cancelWatch];
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch_async(_fileChangeQueue, ^{
|
||||
if (self.currentFile && ![self.currentFile isEqualToString:filename])
|
||||
{
|
||||
[self cancelWatch];
|
||||
}
|
||||
|
||||
dispatch_async(_fileChangeQueue, ^{
|
||||
NSData *fileData = [NSData dataWithContentsOfFile:filename];
|
||||
[self watchPath:filename];
|
||||
[self processFileData:fileData];
|
||||
|
|
@ -160,7 +167,6 @@
|
|||
|
||||
if (fileAttributedString && [documentAttributes[NSDocumentTypeDocumentAttribute] isEqualToString:NSPlainTextDocumentType])
|
||||
{
|
||||
self.attributedText = nil;
|
||||
//self.currentFile = filename;
|
||||
NSString *fileText = fileAttributedString.string;
|
||||
|
||||
|
|
@ -192,7 +198,8 @@
|
|||
fileText = [fileText stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
|
||||
}
|
||||
|
||||
self.text = fileText;
|
||||
|
||||
self.attributedText = [[NSAttributedString alloc] initWithString:fileText attributes:self.defaultAttributes];
|
||||
} else if (fileAttributedString) {
|
||||
[fileAttributedString beginEditing];
|
||||
[fileAttributedString enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, fileAttributedString.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
|
||||
|
|
@ -202,7 +209,7 @@
|
|||
[fileAttributedString addAttribute:NSFontAttributeName value:newFont range:range];
|
||||
}];
|
||||
[fileAttributedString endEditing];
|
||||
self.text = nil;
|
||||
//self.text = nil;
|
||||
self.attributedText = fileAttributedString;
|
||||
}
|
||||
}
|
||||
|
|
@ -231,18 +238,18 @@
|
|||
int fd = open([filePath UTF8String], O_EVTONLY);
|
||||
__block typeof(self) blockSelf = self;
|
||||
|
||||
_fileSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, fd, DISPATCH_VNODE_DELETE | DISPATCH_VNODE_WRITE | DISPATCH_VNODE_EXTEND | DISPATCH_VNODE_ATTRIB | DISPATCH_VNODE_LINK | DISPATCH_VNODE_RENAME | DISPATCH_VNODE_REVOKE, _fileChangeQueue);
|
||||
_fileSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_VNODE, fd, DISPATCH_VNODE_DELETE | DISPATCH_VNODE_WRITE | DISPATCH_VNODE_RENAME | DISPATCH_VNODE_REVOKE, _fileChangeQueue);
|
||||
|
||||
dispatch_source_set_event_handler(_fileSource, ^{
|
||||
unsigned long flags = dispatch_source_get_data(blockSelf->_fileSource);
|
||||
|
||||
//NSLog(@"FLAGS %lu", flags);
|
||||
if (flags & DISPATCH_VNODE_DELETE)
|
||||
{
|
||||
dispatch_source_cancel(blockSelf->_fileSource);
|
||||
blockSelf->_fileSource = NULL;
|
||||
[blockSelf watchPath:filePath];
|
||||
} else {
|
||||
[self openFile:filePath];
|
||||
[self openFile:filePath];
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1019,7 +1019,6 @@ OSStatus encoderRenderCallback( void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
|||
CAMultiAudioOutputTrack *outputTrack = self.outputTracks[trackUID];
|
||||
if (outputTrack)
|
||||
{
|
||||
NSLog(@"STARTING ENCODER FOR %@", trackUID);
|
||||
CAMultiAudioNode *renderNode = outputTrack.encoderNode;
|
||||
CSAacEncoder *encoder = outputTrack.encoder;
|
||||
AudioUnitAddRenderNotify(renderNode.audioUnit, encoderRenderCallback, [encoder inputBufferPtr]);
|
||||
|
|
|
|||
|
|
@ -227,8 +227,7 @@
|
|||
}
|
||||
[outputsForBus addObject:[[CAMultiAudioConnection alloc] initWithNode:toNode bus:inBus]];
|
||||
toNode.inputConnections[@(inBus)] = [[CAMultiAudioConnection alloc] initWithNode:node bus:outBus];
|
||||
NSLog(@"%@ OUTPUT %@", node, [node outputFormatForBus:outBus]);
|
||||
NSLog(@"%@ INPUT %@", toNode, [toNode inputFormatForBus:inBus]);
|
||||
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -512,7 +512,7 @@
|
|||
elapsed_t = end_t - start_t;
|
||||
if (elapsed_t > 1.0f/60.0f)
|
||||
{
|
||||
NSLog(@"RENDER TOOK %f", elapsed_t);
|
||||
NSLog(@"RENDER TOOK %f %@", elapsed_t, NSThread.currentThread);
|
||||
}
|
||||
if (self.frameReadyBlock)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -683,7 +683,7 @@ static NSArray *_sourceTypes = nil;
|
|||
{
|
||||
[CATransaction begin];
|
||||
updateBlock(_currentLayer);
|
||||
[_currentLayer setNeedsDisplay];
|
||||
[_currentLayer displayIfNeeded];
|
||||
[CATransaction commit];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -354,9 +354,11 @@
|
|||
{
|
||||
|
||||
|
||||
CALayer *newLayer = [self createNewLayer];
|
||||
CALayer *newLayer = nil;
|
||||
@synchronized(self)
|
||||
{
|
||||
newLayer = [self createNewLayer];
|
||||
|
||||
if (!self.tickInput)
|
||||
{
|
||||
self.tickInput = inputsrc;
|
||||
|
|
|
|||
|
|
@ -51,9 +51,17 @@
|
|||
-(CALayer *)createNewLayer
|
||||
{
|
||||
CATextLayer *newLayer = [CATextLayer layer];
|
||||
newLayer.string = _attribString;
|
||||
|
||||
newLayer.bounds = CGRectMake(0.0, 0.0, _attribString.size.width, _attribString.size.height);
|
||||
NSMutableAttributedString *aStr = nil;
|
||||
@synchronized (self) {
|
||||
aStr = _attribString;
|
||||
}
|
||||
|
||||
if (aStr)
|
||||
{
|
||||
newLayer.string = _attribString;
|
||||
newLayer.bounds = CGRectMake(0.0, 0.0, aStr.size.width, aStr.size.height);
|
||||
}
|
||||
newLayer.alignmentMode = self.alignmentMode;
|
||||
newLayer.wrapped = self.wrapped;
|
||||
return newLayer;
|
||||
|
|
@ -150,14 +158,18 @@
|
|||
{
|
||||
|
||||
NSDictionary *strAttrs = self.defaultAttributes;
|
||||
NSMutableAttributedString *newAttribString = nil;
|
||||
if (self.attributedText)
|
||||
{
|
||||
_attribString = self.attributedText.mutableCopy;
|
||||
newAttribString = self.attributedText.mutableCopy;
|
||||
} else {
|
||||
|
||||
_attribString = [[NSMutableAttributedString alloc] initWithString:self.text attributes:strAttrs];
|
||||
newAttribString = [[NSMutableAttributedString alloc] initWithString:self.text attributes:strAttrs];
|
||||
}
|
||||
|
||||
@synchronized (self) {
|
||||
_attribString = newAttribString;
|
||||
}
|
||||
if ([self.alignmentMode isEqualToString:kCAAlignmentCenter] || [self.alignmentMode isEqualToString:kCAAlignmentRight])
|
||||
{
|
||||
self.allowScaling = YES;
|
||||
|
|
@ -168,7 +180,8 @@
|
|||
|
||||
[self updateLayersWithBlock:^(CALayer *layer) {
|
||||
//layer.bounds = CGRectMake(0.0, 0.0, self->_attribString.size.width, self->_attribString.size.height);
|
||||
((CATextLayer *)layer).string = self->_attribString;
|
||||
|
||||
((CATextLayer *)layer).string = newAttribString;
|
||||
((CATextLayer *)layer).alignmentMode = self.alignmentMode;
|
||||
((CATextLayer *)layer).wrapped = self.wrapped;
|
||||
}];
|
||||
|
|
@ -193,14 +206,12 @@
|
|||
_attributedText = attributedText;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
self.captureName = attributedText.string;
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
[self buildString];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue