Files
ghostgram/submodules/TelegramUI/Components/RichTextEditor/Sources/RichTextInputDecUpstream/TextView/IDRichTextPosition.m
T
ichmagmaus111andClaude Opus 5.5 534cabe35b bug fixes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 16:55:08 +01:00

64 lines
1.9 KiB
Objective-C

#import <TargetConditionals.h>
#if TARGET_OS_IOS
#import "IDRichTextPosition.h"
#import "IDBlockDocument.h"
#import "IDCanonicalTextProjection.h"
@interface IDRichTextPosition ()
@property(nonatomic, strong, readwrite) IDRichTextAnchor *anchor;
@property(nonatomic, readwrite) UITextStorageDirection affinity;
@property(nonatomic, readwrite) NSUInteger documentRevision;
@end
@implementation IDRichTextPosition
- (instancetype)initWithAnchor:(IDRichTextAnchor *)anchor
affinity:(UITextStorageDirection)affinity {
IDBlockDocument *document = anchor.document;
if (document == nil) {
[NSException raise:NSInvalidArgumentException
format:@"Rich text positions require an anchor with a live document."];
}
self = [super init];
if (self != nil) {
_anchor = anchor;
_affinity = affinity;
_documentRevision = document.documentRevision;
}
return self;
}
- (id)copyWithZone:(NSZone *)zone {
return self;
}
- (BOOL)isEqual:(id)object {
if (object == self) return YES;
if (![object isKindOfClass:IDRichTextPosition.class]) return NO;
IDRichTextPosition *other = object;
IDBlockDocument *document = self.anchor.document;
if (document == nil || document != other.anchor.document) {
return NO;
}
IDCanonicalTextProjection *projection =
[[IDCanonicalTextProjection alloc] initWithDocument:document];
return [self.anchor canonicalOffsetInProjection:projection] ==
[other.anchor canonicalOffsetInProjection:projection];
}
- (NSUInteger)hash {
IDBlockDocument *document = self.anchor.document;
if (document == nil) return (NSUInteger)(__bridge void *)self;
IDCanonicalTextProjection *projection =
[[IDCanonicalTextProjection alloc] initWithDocument:document];
NSUInteger offset = [self.anchor canonicalOffsetInProjection:projection];
return document.hash ^ (offset * 31U);
}
@end
#endif