Skip to content

Commit

Permalink
textSet -> characterIndexes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Apr 6, 2024
1 parent d81d888 commit 28adcfc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies: [
### `NSTextContainer` Additions

```swift
func textSet(for rect: CGRect) -> IndexSet
func characterIndexes(within rect: CGRect) -> IndexSet
func enumerateLineFragments(for rect: CGRect, strictIntersection: Bool, block: (CGRect, NSRange, inout Bool) -> Void)
func enumerateLineFragments(in range: NSRange, block: (CGRect, NSRange, inout Bool) -> Void)
```
Expand All @@ -45,8 +45,9 @@ func enumerateLineFragments(with provider: NSTextElementProvider, block: (NSText

### `NSTextView`/`UITextView` Additions

```swift
var visibleTextSet: IndexSet
```
func characterIndexes(within rect: CGRect) -> IndexSet
var visibleCharacterIndexes: IndexSet
```

## Contributing and Collaboration
Expand Down
2 changes: 1 addition & 1 deletion Sources/Glyph/NSTextContainer+Additions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extension NSTextContainer {
}

/// Returns an IndexSet representing the content within `rect`.
public func textSet(for rect: CGRect) -> IndexSet {
public func characterIndexes(within rect: CGRect) -> IndexSet {
var set = IndexSet()

enumerateLineFragments(for: rect, strictIntersection: true) { _, range, _ in
Expand Down
10 changes: 5 additions & 5 deletions Sources/Glyph/NSTextView+Additions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ extension TextView {
}

/// Returns an IndexSet representing the content within `rect`.
public func textSet(for rect: CGRect) -> IndexSet {
public func characterIndexes(within rect: CGRect) -> IndexSet {
#if os(macOS) && !targetEnvironment(macCatalyst)
return textContainer?.textSet(for: rect) ?? IndexSet()
return textContainer?.characterIndexes(within: rect) ?? IndexSet()
#elseif os(iOS) || os(visionOS)
return textContainer.textSet(for: rect)
return textContainer.characterIndexes(within: rect)
#endif
}

/// Returns an IndexSet representing the visible content.
public var visibleTextSet: IndexSet {
textSet(for: visibleContainerRect)
public var visibleCharacterIndexes: IndexSet {
characterIndexes(within: visibleContainerRect)
}
}
#endif

0 comments on commit 28adcfc

Please sign in to comment.