Renamed NSIndexPath+MPRemoveFirstIndex Category to NSIndexPath+MPReverseIndexPath
Added MPDisplayExtension Category to MPExpression and MPFunction Added Methods to Invalidate the Cache to MPExpressionLayout and MPFunctionLayout
This commit is contained in:
21
MathPad/MPDisplayExtension.h
Normal file
21
MathPad/MPDisplayExtension.h
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// MPExpression+MPDisplayExtension.h
|
||||
// MathPad
|
||||
//
|
||||
// Created by Kim Wittenburg on 23.04.14.
|
||||
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPModel.h"
|
||||
|
||||
@interface MPExpression (MPDisplayExtension)
|
||||
|
||||
- (void)subexpressionChangedAtRangePath:(MPRangePath *)rangePath;
|
||||
|
||||
@end
|
||||
|
||||
@interface MPFunction (MPDisplayExtension)
|
||||
|
||||
- (void)subexpressionChangedAtRangePath:(MPRangePath *)rangePath;
|
||||
|
||||
@end
|
||||
33
MathPad/MPDisplayExtension.m
Normal file
33
MathPad/MPDisplayExtension.m
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// MPExpression+MPDisplayExtension.m
|
||||
// MathPad
|
||||
//
|
||||
// Created by Kim Wittenburg on 23.04.14.
|
||||
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPDisplayExtension.h"
|
||||
|
||||
@implementation MPExpression (MPDisplayExtension)
|
||||
|
||||
- (void)subexpressionChangedAtRangePath:(MPRangePath *)rangePath
|
||||
{
|
||||
NSUInteger index = [self.parent indexOfChild:self];
|
||||
NSIndexPath *newLocation = [rangePath.location indexPathByPrecedingIndex:index];
|
||||
[self.parent subexpressionChangedAtRangePath:[[MPRangePath alloc] initWithLocation:newLocation
|
||||
length:rangePath.length]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation MPFunction (MPDisplayExtension)
|
||||
|
||||
- (void)subexpressionChangedAtRangePath:(MPRangePath *)rangePath
|
||||
{
|
||||
NSUInteger index = [self.parent indexOfSymbol:self];
|
||||
NSIndexPath *newLocation = [rangePath.location indexPathByPrecedingIndex:index];
|
||||
[self.parent subexpressionChangedAtRangePath:[[MPRangePath alloc] initWithLocation:newLocation
|
||||
length:rangePath.length]];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -74,6 +74,7 @@
|
||||
- (void)invalidate
|
||||
{
|
||||
_valid = NO;
|
||||
[self.parent invalidate];
|
||||
}
|
||||
|
||||
- (void)expressionEditedInRange:(NSRange)range replacementLength:(NSUInteger)length
|
||||
@@ -86,7 +87,7 @@
|
||||
[newPlaceholders addObject:[NSNull null]];
|
||||
}
|
||||
[_symbolCache replaceObjectsInRange:range withObjectsFromArray:newPlaceholders];
|
||||
_valid = NO;
|
||||
[self invalidate];
|
||||
}
|
||||
|
||||
- (BOOL)hasCacheForSymbolAtIndex:(NSUInteger)index
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#pragma mark Cache Methods
|
||||
|
||||
- (void)invalidate;
|
||||
- (void)editedChildAtIndex:(NSUInteger)index;
|
||||
|
||||
- (BOOL)hasCacheForChildAtIndex:(NSUInteger)index;
|
||||
- (MPExpressionLayout *)expressionLayoutForChildAtIndex:(NSUInteger)index;
|
||||
|
||||
@@ -73,6 +73,15 @@
|
||||
- (void)invalidate
|
||||
{
|
||||
_valid = NO;
|
||||
[self.parent invalidate];
|
||||
}
|
||||
|
||||
- (void)editedChildAtIndex:(NSUInteger)index
|
||||
{
|
||||
if ([self hasCacheForChildAtIndex:index]) {
|
||||
_childCache[index] = [NSNull null];
|
||||
}
|
||||
[self invalidate];
|
||||
}
|
||||
|
||||
- (BOOL)hasCacheForChildAtIndex:(NSUInteger)index
|
||||
|
||||
@@ -16,9 +16,10 @@
|
||||
#import "MPException.h"
|
||||
#import "MPExpression.h"
|
||||
#import "MPFunction.h"
|
||||
#import "MPRangePath.h"
|
||||
|
||||
#import "NSObject+MPStringTest.h"
|
||||
#import "NSTextStorage+MPSetContents.h"
|
||||
#import "NSIndexPath+MPRemoveFirstIndex.h"
|
||||
#import "NSIndexPath+MPReverseIndexPath.h"
|
||||
|
||||
#endif
|
||||
|
||||
23
MathPad/NSIndexPath+MPReverseIndexPath.h
Normal file
23
MathPad/NSIndexPath+MPReverseIndexPath.h
Normal file
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// NSIndexPath+MPRemoveFirstIndex.h
|
||||
// MathPad
|
||||
//
|
||||
// Created by Kim Wittenburg on 23.04.14.
|
||||
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface NSIndexPath (MPReverseIndexPath)
|
||||
|
||||
/*!
|
||||
@method indexPathByRemovingFirstIndex
|
||||
@brief Provides an index path with the indexes in the receiving index path, excluding the first one.
|
||||
@discussion Returns an empty NSIndexPath instance if the receiving index path’s length is 1 or less.
|
||||
@return New index path with the receiving index path’s indexes, excluding the first one.
|
||||
*/
|
||||
- (NSIndexPath *)indexPathByRemovingFirstIndex;
|
||||
|
||||
- (NSIndexPath *)indexPathByPrecedingIndex:(NSUInteger)index;
|
||||
|
||||
@end
|
||||
37
MathPad/NSIndexPath+MPReverseIndexPath.m
Normal file
37
MathPad/NSIndexPath+MPReverseIndexPath.m
Normal file
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// NSIndexPath+MPRemoveFirstIndex.m
|
||||
// MathPad
|
||||
//
|
||||
// Created by Kim Wittenburg on 23.04.14.
|
||||
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NSIndexPath+MPReverseIndexPath.h"
|
||||
|
||||
@implementation NSIndexPath (MPReverseIndexPath)
|
||||
|
||||
- (NSIndexPath *)indexPathByRemovingFirstIndex
|
||||
{
|
||||
if (self.length <= 1) {
|
||||
return [[NSIndexPath alloc] init];
|
||||
}
|
||||
NSUInteger indexes[self.length];
|
||||
[self getIndexes:indexes];
|
||||
NSUInteger newIndexes[self.length-1];
|
||||
for (NSUInteger i = 0; i < self.length-1; i++) {
|
||||
newIndexes[i] = indexes[i+1];
|
||||
}
|
||||
return [[NSIndexPath alloc] initWithIndexes:newIndexes length:self.length-1];
|
||||
}
|
||||
|
||||
- (NSIndexPath *)indexPathByPrecedingIndex:(NSUInteger)index
|
||||
{
|
||||
NSUInteger newIndexes[self.length+1];
|
||||
newIndexes[0] = index;
|
||||
for (NSUInteger i = 0; i < self.length; i++) {
|
||||
newIndexes[i+1] = [self indexAtPosition:i];
|
||||
}
|
||||
return [[NSIndexPath alloc] initWithIndexes:newIndexes length:self.length+1];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user