Skip to content

Error when trying to edit Matrix #13

@MFJones21

Description

@MFJones21

So I was working on making it possible, so that you could insert an editable Matrix in your editable math label. What I did was inserting this code into MTEditableMathLabel:

`- (void) insertMatrix: (int)rows :(int)columns :(NSString )type
{
MTMathAtom
atom = [MTMathAtomFactory placeholderMatrix:columns :rows :type];

if (_insertionIndex.subIndexType == kMTSubIndexTypeDenominator) {
    if (atom.type == kMTMathAtomRelation) {
        // pull the insertion index out
        _insertionIndex = [[_insertionIndex levelDown] next];
    }
}

if (atom) {
    if (![self updatePlaceholderIfPresent:atom]) {
        // If a placeholder wasn't updated then insert the new element.
        [self.mathList insertAtom:atom atListIndex:_insertionIndex];
    }
    if (atom.type == kMTMathAtomFraction) {
        // go to the numerator
        _insertionIndex = [_insertionIndex levelUpWithSubIndex:[MTMathListIndex level0Index:0] type:kMTSubIndexTypeNumerator];
    } else {
        _insertionIndex = _insertionIndex.next;
    }
}

self.label.mathList = self.mathList;
[self insertionPointChanged];

if ([self.delegate respondsToSelector:@selector(textModified:)]) {
    [self.delegate textModified:self];
}

}`

and this code into MTMathAtomFactory

`+ (MTMathAtom *)placeholderMatrix: (int)width :(int)height :(NSString )envname
{
NSError
error;

NSMutableArray<NSMutableArray<MTMathList*>*>* rows = [[NSMutableArray alloc] initWithCapacity:(NSInteger)height];
for (int y = 0; y < height; y++)
{
    NSMutableArray<MTMathList*>* row = [[NSMutableArray alloc] initWithCapacity:(NSInteger)width];
    
    for (int x = 0; x < width; x++)
    {
        MTMathList* list = [MTMathList new];
        
        [list addAtom:[self placeholder]];
        
        row[x] = list;
    }
    
    rows[y] = row;
}
MTMathAtom* table = [MTMathAtomFactory tableWithEnvironment:envname rows:rows error:&error];

return table;

}`

This displays the matrix fine, but when I try to select one of the Values in the matrix I get this error, which I have no idea where it is coming from.

'MTLine type regular inside an MTLine - shouldn't happen'

But the display is exactly the way I want it to be. What is wrong here ? I really need help on this please. Thanks a lot for any help in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions