Skip to content

Commit

Permalink
Backport getRectForCharRange to 0.73-stable (#2141)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saadnajmi authored Jun 20, 2024
2 parents 7634dcd + 593fa8d commit 69ec3ae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/react-native/Libraries/Text/Text/RCTTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ NS_ASSUME_NONNULL_BEGIN
contentFrame:(CGRect)contentFrame
descendantViews:(NSArray<RCTPlatformView *> *)descendantViews; // [macOS]

#if TARGET_OS_OSX // [macOS
- (NSRect)getRectForCharRange:(NSRange)charRange;
#endif // macOS]

/**
* (Experimental and unused for Paper) Pointer event handlers.
*/
Expand Down
16 changes: 16 additions & 0 deletions packages/react-native/Libraries/Text/Text/RCTTextView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,22 @@ - (void)setTextStorage:(NSTextStorage *)textStorage
[self setNeedsDisplay];
}

#if TARGET_OS_OSX // [macOS
- (NSRect)getRectForCharRange:(NSRange)charRange
{
if (_textStorage) {
NSLayoutManager *layoutManager = _textStorage.layoutManagers.firstObject;
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;
if (layoutManager && textContainer) {
NSRange glyphRange = [layoutManager glyphRangeForCharacterRange:charRange actualCharacterRange:nullptr];
return [layoutManager boundingRectForGlyphRange:glyphRange inTextContainer:textContainer];
}
}

return {0, 0, 0, 0};
}
#endif // macOS]

- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
Expand Down

0 comments on commit 69ec3ae

Please sign in to comment.