-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Direct text storage attribute modifications #33
Comments
Yeah, thinking about this more, I believe we might have been rushing a little too fast. While it is easy to create your own |
In a regular rich text Since the approach of storing attributes interferes wins over the text storage's attribute fixing procedure (which IIRC incorporates temporary attributes from the layout manager), the only solution I found myself is to tell the text storage what to use by default instead. I'll show you some code in a minute @mattmassicotte |
Sorry for not being sufficiently diligent! It looked alright until I added more font settings, so that was a sad surprise indeed. |
Absolutely no need to apologize! I like working quickly, and it's ok for I think it may make sense to factor out these two different modes into dedicated |
I opened #34 with a proposed solution that leans fully into stored attributes. Splitting this into two separate approaches, one for computed, temporary attributes, and one for stored attributes, sounds sensible (e.g. to enable checking on TextKit 2 updates, like for fixes to #20) and a maintenance nightmare both, though. I'm with @MrNoodle from 2012, and @danielpunkass (ca 2017 AppKit Abusers) since MarsEdit's font is not allowed to change. This all makes sense, highlighting is not part of the document, so don't store it in the text storage. Jakob Egger in 2017 also pointed out (in the comments) that this can be achieved by having a separate attribute storage just for the highlighter attributes. Then applying attributes won't again trigger If not setting fonts is fine, by all means we should undo my changes :) |
I read though that post as well as the comment you referenced. My opinion is that the text storage should represent the actual text data. Highlighting can be derived from it, but doesn't have to be stored there just because it is convenient to do so. I'm very into the idea of a separate highlighting attribute storage. However! I'm really interested in making this system compatible with whatever means you want to use. I don't want my opinion to matter. And, the whole point of
This way, users of Neon can decide how they'd like it all to work. Plus, you can always just side-step the entire thing and make your own |
I also want to point out that there is comment in that blog post I'm very skeptical of:
I bet the issue here is not that modifying the storage is slow, but that modifying it this way is causing synchronous layout work to happen, and that is slow. Layout, in general, is extremely expensive. This can be a serious performance issue even if you are really careful with your invalidation ranges, which Neon is. This is one the reasons temporary attributes are great - they do not affect layout. |
That does make sense in hindsight! Hmm I do believe we didn't try in earnest to limit layout-affecting attributes (actually mostly
While I believe that the demo now is more powerful and impressive for folks interested in getting a highlighter demo to work, the downsides are apparent. I could implement these components in my simple code editor just as well. So it's not like I couldn't use Neon, personally, unless the convenience components have these features! To make these changes, do you believe there's any value in separating a Neon core from the selection of convenience kickstarter components in a separate package target? (Or two, one per approach) |
I am, in fact, thinking a lot about this package and how it will be organized. More to come on that front soon! But, for the immediate problem, I think all we need to do is refactor this a little bit so the user has more control. I think the best approach is to move this decision about highlighting into specialized |
Ok, here's what I've done.
I also make use of NSTextView's Overall, I think this is a good change. TextViewHighlighter is now more flexible, and there are built-in solutions for the most common Apple text view configurations. This will require a little bit of code change on your end though. You'll now need to supply a |
Wow, that was quick and very thorough! I'll check things out ASAP, thank you |
Works fine with the manual selection 👍 |
#28 and #31 brings up the common problem of attribute invalidation. Using temporary attributes has a big advantage, because it gives you another "layer" of attributes.
Many users have run into issues when not using temporary attributes in the past. Let's talk about possible solutions.
The text was updated successfully, but these errors were encountered: