-
Notifications
You must be signed in to change notification settings - Fork 107
Description
Right now, CodeEditTextView attempts to render every line of text at once. This leads to a large reduction in performance for files that extend beyond the bounds of the visible text as that text is always rendered. This isn't a problem for syntax highlighting, as the highlighter only uses the text that is visible, but any text that is being rendered that isn't visible is wasted CPU resources.
The root cause is this line in STTextView
, where TextKit asks a NSTextViewportLayoutControllerDelegate
for the bounds to render. In the current implementation, STTextView
returns the entire bounds of the text view, effectively telling TextKit to render the entire document.
public func viewportBounds(for textViewportLayoutController: NSTextViewportLayoutController) -> CGRect {
// Return bounds until resolve bounds problem
return bounds
The comments in the implementation say that the view lays out the entire document because layout fragments outside the viewport are broken, which if I'm not mistaken is the expected result. One of the benefits of TextKit2 is that it only lays out text in the viewport, so any layout fragments outside the viewport will of course be broken. This also, of course, breaks the ruler view.
The solution for the ruler view is to calculate line heights starting at the first rendered line, instead of the actual first line. If we align the first rendered lines in both the text view and the ruler view, it will appear that all drawn lines are lined up with their corresponding text lines. This will also make the ruler view more performant.
I've already been able to fix the viewport calculation problem using a custom delegate class, and @ben-p-commits mentioned on Discord they'd be willing to take on the ruler view. Both changes will have to be merged at the same time so this issue is to track this.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status