Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions ios/utils/LayoutManagerExtension.mm
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,29 @@ - (void)my_drawBackgroundForGlyphRange:(NSRange)glyphRange
return;
}

NSRange inputRange = NSMakeRange(0, typedInput->textView.textStorage.length);

[self drawBlockQuotes:typedInput origin:origin inputRange:inputRange];
[self drawLists:typedInput origin:origin inputRange:inputRange];
[self drawCodeBlocks:typedInput origin:origin inputRange:inputRange];
NSRange visibleCharRange = [self characterRangeForGlyphRange:glyphRange
actualGlyphRange:NULL];

[self drawBlockQuotes:typedInput
origin:origin
visibleCharRange:visibleCharRange];
[self drawLists:typedInput origin:origin visibleCharRange:visibleCharRange];
[self drawCodeBlocks:typedInput
origin:origin
visibleCharRange:visibleCharRange];
}

- (void)drawCodeBlocks:(EnrichedTextInputView *)typedInput
origin:(CGPoint)origin
inputRange:(NSRange)inputRange {
visibleCharRange:(NSRange)visibleCharRange {
CodeBlockStyle *codeBlockStyle =
typedInput->stylesDict[@([CodeBlockStyle getStyleType])];
if (codeBlockStyle == nullptr) {
return;
}

NSArray<StylePair *> *allCodeBlocks =
[codeBlockStyle findAllOccurences:inputRange];
[codeBlockStyle findAllOccurences:visibleCharRange];
NSArray<StylePair *> *mergedCodeBlocks =
[self mergeContiguousStylePairs:allCodeBlocks];
UIColor *bgColor = [[typedInput->config codeBlockBgColor]
Expand Down Expand Up @@ -198,16 +203,14 @@ - (void)drawCodeBlocks:(EnrichedTextInputView *)typedInput

- (void)drawBlockQuotes:(EnrichedTextInputView *)typedInput
origin:(CGPoint)origin
inputRange:(NSRange)inputRange {
visibleCharRange:(NSRange)visibleCharRange {
BlockQuoteStyle *bqStyle =
typedInput->stylesDict[@([BlockQuoteStyle getStyleType])];
if (bqStyle == nullptr) {
return;
}

// it isn't the most performant but we have to check for all the blockquotes
// each time and redraw them
NSArray *allBlockquotes = [bqStyle findAllOccurences:inputRange];
NSArray *allBlockquotes = [bqStyle findAllOccurences:visibleCharRange];

for (StylePair *pair in allBlockquotes) {
NSRange paragraphRange = [typedInput->textView.textStorage.string
Expand Down Expand Up @@ -240,8 +243,8 @@ - (void)drawBlockQuotes:(EnrichedTextInputView *)typedInput
}

- (void)drawLists:(EnrichedTextInputView *)typedInput
origin:(CGPoint)origin
inputRange:(NSRange)inputRange {
origin:(CGPoint)origin
visibleCharRange:(NSRange)visibleCharRange {
UnorderedListStyle *ulStyle =
typedInput->stylesDict[@([UnorderedListStyle getStyleType])];
OrderedListStyle *olStyle =
Expand All @@ -250,10 +253,9 @@ - (void)drawLists:(EnrichedTextInputView *)typedInput
return;
}

// also not the most performant but we redraw all the lists
NSMutableArray *allLists = [[NSMutableArray alloc] init];
[allLists addObjectsFromArray:[ulStyle findAllOccurences:inputRange]];
[allLists addObjectsFromArray:[olStyle findAllOccurences:inputRange]];
[allLists addObjectsFromArray:[ulStyle findAllOccurences:visibleCharRange]];
[allLists addObjectsFromArray:[olStyle findAllOccurences:visibleCharRange]];

for (StylePair *pair in allLists) {
NSParagraphStyle *pStyle = (NSParagraphStyle *)pair.styleValue;
Expand Down
Loading