Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextStorageSystemInterface does not style textedits that are not at end of string #43

Open
Wouter01 opened this issue Mar 17, 2024 · 2 comments

Comments

@Wouter01
Copy link
Contributor

When using TextStorageSystemInterface, initial highlighting works fine. Adding text to the end of the file works fine too. Adding text somewhere else doesn't seem to highlight it.

I did some digging and couldn't find an immediate reason why it's happening. In the beginValidation function (RangeValidator.swift), the following line will return .none, which is probably unexpected.

guard let neededRange = nextNeededRange(in: set, prioritizing: range) else { return .none }

Reproducing the issue: open the sample project, in TextViewSystemInterface comment out the first two interfaces in effectiveInterface, so the TextStorageSystemInterface is used. Then, try editing the text somewhere in the middle.

@mattmassicotte
Copy link
Contributor

Ok reproduced. Also not sure what is wrong. But I suspect it is either timing, or bad interaction between the text view typing attributes and the storage. I don't use storage-based attributes ever myself so I'm not surprised this is problematic.

@mattmassicotte
Copy link
Contributor

Made little process here. Even you force TextViewSystemInterface.effectiveInterface to always return a TextStorageSystemInterface, NSTextView.visibleTextRange will still make use of TextKit2 to calculate the visible ranges. Those calculations are wrong, but I'm not sure yet whether I'm doing it incorrectly or TextKit 2 is just returning in correct results.

But I bet it is TextKit 2 returning stale information because of its async layout calculations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants