Skip to content

Commit

Permalink
Add correct visible range calculation for TextKit 2 (#42)
Browse files Browse the repository at this point in the history
* Add correct visible range calculation for TK2

* replace spaces with tabs
  • Loading branch information
Wouter01 authored Feb 20, 2024
1 parent 3347619 commit 40c3726
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Sources/Neon/NSTextView+VisibleRange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ extension NSTextView {
}

public var visibleTextRange: NSRange {
return textRange(for: visibleRect)
guard
#available(macOS 12.0, *),
let textLayoutManager,
let viewportRange = textLayoutManager.textViewportLayoutController.viewportRange,
let textContentManager = textLayoutManager.textContentManager
else {
return textRange(for: visibleRect)
}

return NSRange(viewportRange, provider: textContentManager)
}
}
#endif

0 comments on commit 40c3726

Please sign in to comment.