Improved Model
Added Keyboard Selection Support Added Mouse Selection Support Added Keyboard Editing Support Corrected Some Bugs Abstracted the Layout System further Added Functions Button (test)
This commit is contained in:
@@ -20,53 +20,20 @@
|
||||
|
||||
@implementation MPExpressionStorage
|
||||
|
||||
- (instancetype)initWithExpressionView:(MPExpressionView *)expressionView elements:(NSArray *)elements
|
||||
{
|
||||
self = [self initWithElements:elements];
|
||||
if (self) {
|
||||
_expressionView = expressionView;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithElements:(NSArray *)elements
|
||||
{
|
||||
self = [super initWithElements:elements];
|
||||
if (self) {
|
||||
_rootLayout = [[MPExpressionLayout alloc] initRootLayoutWithExpressionStorage:self];
|
||||
_rootLayout = [[MPExpressionLayout alloc] initRootLayoutWithExpression:self];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSLayoutManager *)layoutManager
|
||||
- (void)setExpressionView:(MPExpressionView *)expressionView
|
||||
{
|
||||
[self ensureTextSystemObjects];
|
||||
return _layoutManager;
|
||||
}
|
||||
|
||||
- (NSTextContainer *)textContainer
|
||||
{
|
||||
[self ensureTextSystemObjects];
|
||||
return _textContainer;
|
||||
}
|
||||
|
||||
- (NSTextStorage *)textStorage
|
||||
{
|
||||
[self ensureTextSystemObjects];
|
||||
return _textStorage;
|
||||
}
|
||||
|
||||
- (void)ensureTextSystemObjects
|
||||
{
|
||||
if (_layoutManager == nil || _textContainer == nil || _textStorage == nil) {
|
||||
_textStorage = [[NSTextStorage alloc] init];
|
||||
NSTextContainer *textContainer = [[NSTextContainer alloc] initWithContainerSize:NSMakeSize(CGFLOAT_MAX, CGFLOAT_MAX)];
|
||||
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
|
||||
[layoutManager addTextContainer:textContainer];
|
||||
[_textStorage addLayoutManager:layoutManager];
|
||||
_textContainer = textContainer;
|
||||
_layoutManager = layoutManager;
|
||||
}
|
||||
_expressionView = expressionView;
|
||||
self.rootLayout = [[MPExpressionLayout alloc] initRootLayoutWithExpression:self];
|
||||
self.rootLayout.flipped = expressionView.isFlipped;
|
||||
}
|
||||
|
||||
- (void)didChangeElementsInRangePath:(MPRangePath *)rangePath
|
||||
@@ -76,11 +43,13 @@
|
||||
return;
|
||||
}
|
||||
MPLayout *current = self.rootLayout;
|
||||
for (NSUInteger index = 1; index < rangePath.location.length-1; index++) {
|
||||
for (NSUInteger position = 0; position < rangePath.location.length-1; position++) {
|
||||
NSUInteger index = [rangePath.location indexAtPosition:position];
|
||||
current = [current childLayoutAtIndex:index];
|
||||
}
|
||||
[current clearCacheInRange:rangePath.rangeAtLastIndex
|
||||
replacementLength:replacementLength];
|
||||
[self.expressionView invalidateIntrinsicContentSize];
|
||||
self.expressionView.needsDisplay = YES;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user