Skip to content

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

@sanketj

Description

@sanketj

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions