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

[css-highlight-api] Should priority be expressed on ::highlight instead of the Highlight object? #4613

Closed
sanketj opened this issue Dec 18, 2019 · 2 comments

Comments

@sanketj
Copy link
Member

sanketj commented Dec 18, 2019

It occurred to me while thinking about #4579 that ::selection and ::inactive-selection are an example of two pseudo elements that target the same set of ranges.

To emulate this with custom highlights, we would currently have to do something like:

:root::highlight(active-selection-ranges) {
  /* active selection style */
}
:root::highlight(inactive-selection-ranges) {
  /* inactive selection style */
}

Here, active-selection-ranges and inactive-selection-ranges are Highlight objects. In order for inactive selection highlights to layer on top of active selection highlights, we can assign inactive-selection-ranges the higher priority of the two. Then, if our custom selection transitions from active to inactive, we could either add ranges from active-selection-ranges to inactive-selection-ranges - which is cumbersome - or we could use the inline style attribute to reverse the styles - which is ugly because active-selection-ranges will then have inactive styles.

If we could express priority on the ::highlight pseudo instead of the Highlight object, then we could do the following:

:root::highlight(selection-ranges) {
  /* active selection style */
}
:root::highlight(selection-ranges) {
  /* inactive selection style */
}

Now we can just have one Highlight object and we only need to modify its priority as we transition from one selection state to another. If the selection should start off active, we can start the active selection highlight at a higher priority, and once the selection becomes inactive, we can lower its priority below that of the inactive selection highlight.

@frivoal frivoal changed the title [css-highlight-api] Should priority be expressed on ::highlight instead of HighlightRangeGroup? [css-highlight-api] Should priority be expressed on ::highlight instead of the Highlight object? Dec 20, 2019
@fantasai
Copy link
Collaborator

There isn't any case in which the specificity differs betwee two rules with identical selectors. CSS has always defined that the following:

selector { /* declaration block 2 */ }
selector { /* declaration block 2 */ }

is equivalent to

selector { /* declaration block 1*/ /* declaration block 2 */

I don't think it's a good idea to change this invariant.

Imho the way declaration blocks are split into style rules is a tool for the author to organize the style sheet; we shouldn't try to turn it into a semantic concept.

@sanketj
Copy link
Member Author

sanketj commented Dec 23, 2019

Thinking about this some more, I agree. I think one pseudo element per unique pseudo element selector is an invariant as well. Assuming that is true, then what we have today is the right answer - separate Highlight objects for active and inactive selection. That would also indicate that the answer for the ::selection vs ::inactive-selection case (#4579) is also separate pseudos.

@sanketj sanketj closed this as completed Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants