mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
[WIP] Quotes
This commit is contained in:
@@ -244,6 +244,11 @@
|
||||
[super scrollRectToVisible:rect animated:false];
|
||||
}
|
||||
|
||||
- (CGRect)caretRectForPosition:(UITextPosition *)position {
|
||||
CGRect rect = [super caretRectForPosition:position];
|
||||
return rect;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
|
||||
@@ -501,6 +506,9 @@
|
||||
- (void)setTextContainerInset:(UIEdgeInsets)textContainerInset
|
||||
{
|
||||
AS::MutexLocker l(_textKitLock);
|
||||
|
||||
textContainerInset.top += 12.0;
|
||||
textContainerInset.bottom += 12.0;
|
||||
|
||||
_textContainerInset = textContainerInset;
|
||||
_textKitComponents.textView.textContainerInset = textContainerInset;
|
||||
@@ -1062,8 +1070,68 @@
|
||||
return [_wordKerner layoutManager:layoutManager boundingBoxForControlGlyphAtIndex:glyphIndex forTextContainer:textContainer proposedLineFragment:proposedRect glyphPosition:glyphPosition characterIndex:characterIndex];
|
||||
}
|
||||
|
||||
- (CGFloat)layoutManager:(NSLayoutManager *)layoutManager paragraphSpacingBeforeGlyphAtIndex:(NSUInteger)glyphIndex withProposedLineFragmentRect:(CGRect)rect {
|
||||
int characterIndex = (int)[layoutManager characterIndexForGlyphAtIndex:glyphIndex];
|
||||
if (characterIndex < 0 || characterIndex >= layoutManager.textStorage.length) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
NSDictionary *attributes = [layoutManager.textStorage attributesAtIndex:characterIndex effectiveRange:nil];
|
||||
NSObject *blockQuote = attributes[@"Attribute__Blockquote"];
|
||||
if (blockQuote == nil) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
if (characterIndex != 0) {
|
||||
NSDictionary *previousAttributes = [layoutManager.textStorage attributesAtIndex:characterIndex - 1 effectiveRange:nil];
|
||||
NSObject *previousBlockQuote = previousAttributes[@"Attribute__Blockquote"];
|
||||
if (previousBlockQuote != nil && [blockQuote isEqual:previousBlockQuote]) {
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
return 12.0f;
|
||||
}
|
||||
|
||||
- (CGFloat)layoutManager:(NSLayoutManager *)layoutManager paragraphSpacingAfterGlyphAtIndex:(NSUInteger)glyphIndex withProposedLineFragmentRect:(CGRect)rect {
|
||||
int characterIndex = (int)[layoutManager characterIndexForGlyphAtIndex:glyphIndex];
|
||||
characterIndex--;
|
||||
if (characterIndex < 0) {
|
||||
characterIndex = 0;
|
||||
}
|
||||
if (characterIndex < 0 || characterIndex >= layoutManager.textStorage.length) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
NSDictionary *attributes = [layoutManager.textStorage attributesAtIndex:characterIndex effectiveRange:nil];
|
||||
NSObject *blockQuote = attributes[@"Attribute__Blockquote"];
|
||||
if (blockQuote == nil) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
if (characterIndex + 1 < layoutManager.textStorage.length) {
|
||||
NSDictionary *nextAttributes = [layoutManager.textStorage attributesAtIndex:characterIndex + 1 effectiveRange:nil];
|
||||
NSObject *nextBlockQuote = nextAttributes[@"Attribute__Blockquote"];
|
||||
if (nextBlockQuote != nil && [blockQuote isEqual:nextBlockQuote]) {
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
return 12.0f;
|
||||
}
|
||||
|
||||
- (BOOL)layoutManager:(NSLayoutManager *)layoutManager shouldSetLineFragmentRect:(inout CGRect *)lineFragmentRect lineFragmentUsedRect:(inout CGRect *)lineFragmentUsedRect baselineOffset:(inout CGFloat *)baselineOffset inTextContainer:(NSTextContainer *)textContainer forGlyphRange:(NSRange)glyphRange {
|
||||
CGFloat fontLineHeight;
|
||||
/*if (layoutManager.textStorage.length != 0) {
|
||||
NSDictionary *attributes = [layoutManager.textStorage attributesAtIndex:0 effectiveRange:nil];
|
||||
NSObject *blockQuote = attributes[@"Attribute__Blockquote"];
|
||||
if (blockQuote != nil) {
|
||||
CGRect rect = *lineFragmentRect;
|
||||
rect.origin.y += 12.0;
|
||||
CGRect usedRect = *lineFragmentUsedRect;
|
||||
usedRect.origin.y += 12.0;
|
||||
}
|
||||
}*/
|
||||
/*CGFloat fontLineHeight;
|
||||
UIFont *baseFont = _baseFont;
|
||||
if (_typingAttributes[NSFontAttributeName] != nil) {
|
||||
baseFont = _typingAttributes[NSFontAttributeName];
|
||||
@@ -1086,7 +1154,7 @@
|
||||
|
||||
*lineFragmentRect = rect;
|
||||
*lineFragmentUsedRect = usedRect;
|
||||
*baselineOffset = *baselineOffset + baselineNudge;
|
||||
*baselineOffset = *baselineOffset + baselineNudge;*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,17 +23,40 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)isSimpleRectangularTextContainer {
|
||||
return false;
|
||||
}
|
||||
|
||||
- (CGRect)lineFragmentRectForProposedRect:(CGRect)proposedRect atIndex:(NSUInteger)characterIndex writingDirection:(NSWritingDirection)baseWritingDirection remainingRect:(nullable CGRect *)remainingRect {
|
||||
CGRect result = [super lineFragmentRectForProposedRect:proposedRect atIndex:characterIndex writingDirection:baseWritingDirection remainingRect:remainingRect];
|
||||
|
||||
/*#if DEBUG
|
||||
if (result.origin.y < 10.0f) {
|
||||
result.size.width -= 21.0f;
|
||||
if (result.size.width < 0.0f) {
|
||||
result.size.width = 0.0f;
|
||||
NSTextStorage *textStorage = self.layoutManager.textStorage;
|
||||
if (textStorage != nil) {
|
||||
NSString *string = textStorage.string;
|
||||
int index = (int)characterIndex;
|
||||
if (index >= 0 && index < string.length) {
|
||||
NSDictionary *attributes = [textStorage attributesAtIndex:index effectiveRange:nil];
|
||||
NSObject *blockQuote = attributes[@"Attribute__Blockquote"];
|
||||
if (blockQuote != nil) {
|
||||
bool isFirstLine = false;
|
||||
if (index == 0) {
|
||||
isFirstLine = true;
|
||||
} else {
|
||||
NSDictionary *previousAttributes = [textStorage attributesAtIndex:index - 1 effectiveRange:nil];
|
||||
NSObject *previousBlockQuote = previousAttributes[@"Attribute__Blockquote"];
|
||||
if (previousBlockQuote == nil) {
|
||||
isFirstLine = true;
|
||||
} else if (![blockQuote isEqual:previousBlockQuote]) {
|
||||
isFirstLine = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isFirstLine) {
|
||||
result.size.width -= 100.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif*/
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user