-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Tweak annotation ordering during modifications #53794
Conversation
As I've continued to use the AnnotatedString type and StyledStrings, I've come across some un-intuitive instances where more "broad" styling attributes override more "specific" attributes. Talking with other people confirms that this isn't just me. Giving the current behaviour some more thought, I've realised that just sorting using the default comparison for UnitRange{Int} doesn't quite produce the most approriate results here. So, I introduce `_annot_sortkey` (which see), that tries to produce a more intuitive results.
Test failures appear unrelated |
If this could be backported to 1.11 that would be nice I think, but I'm not sure how this change fits in with the guidelines on that. |
Let me know if I'm being too ambitious, but I'm going to speculatively tag this with |
On the surface, this looks like a behavioral/api change, so if it isn't backported it would be breaking in 1.12 The fourth example in your status quo screenshot looks like a bug to me. Bugfixes should be backported. Where, if anywhere, is the interpretation for conflicting style annotations specified? I propose that
Which is what most GUI text editors I'm familiar with use (if I select a region and make it red, and then select a larger region and make it green, the red is overridden. But an annotation without precedence could still have an impact, for example if I first annotated a small region bold and then a large region red, the intersection would be bold and red. What I think you are proposing (B) is
Which is a more complicated set of rules than (A). I think that these rules differ when using interpolation (A makes the outer string's annotations take precedence while B gives the inner string precedence iff it does not fill the entire outer face (see table))
Otherwise, they do not differ (as far as I can tell) except when explicitly using the I only have cursory understanding of what's going on here, so lmk if I'm misunderstanding. |
Yea, after I saw that behaviour my reaction was "that's not right". I'd like to see this change merged and backported.
The current interpretation is "last specified wins", the question is: when using the I think when discussing the behaviour, it's worth talking about the @styledWith these changes, I think we can characterise the
and interpolation acts as if you wrote in the value. To clarify by way of an example, with annotate!I believe your interpretation (B) is correct, in that
To take your "highlight a larger region and make it red, and only red" example, I think the way to do that would be not just to apply it later but:
It could be helpful to expose the "remove all annotations in this region" functionality provided by I think the reason why I didn't just go for "later wins" (A) is that the final result of a "later wins" scheme should be able to be represented by a set of annotations that is in the expected order, and it seems nice to have the set of annotations kept in a single ordering when possible. As an aside, if you re-constuct the |
|
There are a few small reasons why annotations are sorted at all. Perhaps this should be re-evaluated entirely, but I think it's good that: (1) having annotations appear sorted by where they start makes it possible to generally look for (and operate on) annotations in a certain region in You're right about removing annotations in the target region perhaps not being the particular behavior wanted, but for that case you can accomplish the result you desire by adding annotations for the same region(s) as existing annotations after them. Since the sorting is all stable, they will override previous attributes (this is all under the annotation interpretation model that I say this not to make the point "it's trivially easy", but that it is very much possible to achieve the result you describe with sorting, and so I think this is best characterised as a tradeoff of convenience. I currently judge the sorting to be worth having, and this scheme to be better, but I'm not dead set on this view by any means. |
After a long chat with @LilithHafner, we're going to be taking a different approach to this. A superseding PR should be up shortly. |
In my estimation, these changes make the sorting, particularly in combination with StyledStrings, more consistent/intuitive.
See the commit message and
_annot_sortkey
docstring for more details.Status quo
With this PR (and JuliaLang/StyledStrings.jl@c21b43e)