zed icon indicating copy to clipboard operation
zed copied to clipboard

[Accessibility] Low contrast / readability of matches, highlights, and selected text.

Open juliangarnier opened this issue 1 year ago • 10 comments

Check for existing issues

  • [X] Completed

Describe the feature

Problem

Selected text, matches and highlights can result in low contrast / unreadable text:

Hard to read text in search results: Screenshot 2024-09-17 at 09 29 56 Screenshot 2024-09-17 at 09 57 50

Selecting a text can in some cases make it harder to read: Screenshot 2024-09-17 at 09 31 20

Matching brackets are almost unnoticeable: Screenshot 2024-09-17 at 10 00 23

Currently themes rely on transparency / blending color for highlights, but this causes a lot of issues (#7333, #17599, #16380, #4678, #4859), and I think they could all be addressed with this:

Solution

Expose an optional foreground color property for each of the different match / highlight / selection styles:

    "search.match_background": "#dfc184ff",
+   "search.match_foreground": "#282c34ff",
    "editor.document_highlight.read_background": "#dfc184ff",
+   "editor.document_highlight.read_foreground": "#282c34ff",
    "editor.document_highlight.write_background": "#dfc184ff",
+   "editor.document_highlight.write_foreground": "#282c34ff",
    "players": [
      {
        "cursor": "#5ac1feff",
        "background": "#5ac1feff",
        "selection": "#dfc184ff"
+       "selection_foreground": "#282c34ff"
      }
    ],

If applicable, add mockups / screenshots to help present your vision of the feature

By manually setting high-contrast background and foreground colors to these properties, we make sure the text will alway be readable in all scenarios:

Screenshot 2024-09-16 at 17 16 11

juliangarnier avatar Sep 16 '24 16:09 juliangarnier

Updated the issue to focus more on the actual problem and suggest a solution.

juliangarnier avatar Sep 17 '24 08:09 juliangarnier

@juliangarnier I'm curious to hear what you think about

  • https://github.com/zed-industries/zed/pull/17606

This PR completely removes color blending with foreground colors, (which is more like how CSS color works)

Text selection is an interesting case.

I'm of the opinion that this is clearer:

image

Than this:

image

I think we have 3 main options:

  1. remove all syntax coloring in selections, make the selection color whatever was specified in your proposed solution
    • personally, my answer here is no, because it will make seeing syntax very difficult if everything is the same color
  2. perform a blend of foreground & background colors using the alpha/opacity value (if present) in editor.document_highlight.read_foreground and editor.document_highlight.write_foreground specifically during selection
  3. continue with the status quo

Chrome & Firefox Selections

I think browsers are a good reference example here as they've spent a lot of time thinking about accessibility, and how they do text selection.

  • They only highlight the background
  • They do not change foreground colors whatsoever
  • (Both chrome & firefox behave in this way)

image


Figma

However, it appears that tools like figma appear to be potentially doing an "overlay" color (over the text) as opposed to a background color (under the text)

image image

image


Relation to my PR

My PR linked above, may partly solve some of these issues, particularly in cases like comments, where currently, most themes use a "gray" color. This breaks accessibility guidelines.

image

Instead, what my PR will enable is the usage of transparent foreground colors, such as #FFF4 to represent a comment via opacity

This is the difference:

image

You can see that the left has better contrast, as the whiteness is applied over the blue selection, whereas on the right, the foreground brightness stays constant (this leads to reduced contrast during selection)

AlbertMarashi avatar Sep 17 '24 17:09 AlbertMarashi

@juliangarnier I'm curious to hear what you think about

I'm guessing you're asking about the remove foreground color blending part? I think it's great! And clearly a step in the right direction for better contrast.

Text selection is an interesting case.

It is but my idea is to provide a more global solution to color highlighting, not only selection.

I think we have 3 main options:

  1. remove all syntax coloring in selections, make the selection color whatever was specified in your proposed solution
    • personally, my answer here is no, because it will make seeing syntax very difficult if everything is the same color

Not exactly. The idea is to have an optional selection_foreground, if not set, then the foreground color stays the same.

There is also the SublimeText way: The selection foreground can be optionally set at the syntax level, allowing fine grained highlighting depending of what part is of the code is selected:

{
    "scope": "comment",
    "foreground": "color(var(grey))",
    "selection_foreground": "color(var(bg2))",
}

https://github.com/user-attachments/assets/6715c84a-cb22-4e0a-a1dd-4c32cfc2db72

  1. perform a blend of foreground & background colors using the alpha/opacity value (if present) in editor.document_highlight.read_foreground and editor.document_highlight.write_foreground specifically during selection

This won't guaranty good contrast though, or requires som contrast checking checking (Sublime allows that at the theme level too like this color(var(bg2) min-contrast(var(selection) 3.5))

  1. continue with the status quo

I think 1. can be implemented without any breaking changes, since this it won't have any effect if a selection_foreground is not defined.

I think it's important to find a general solution that can improves every part of the highlighting system, not only selection. For example, search results highlights, where losing syntax highlighting is less important than losing contrast:

hl2

The nice thing about the solution of adding an optional selection_foreground color is that it doesn't conflict with the curent system, and simply adds more control over contrast when building themes.

juliangarnier avatar Sep 17 '24 19:09 juliangarnier

See also:

  • #15521

notpeter avatar Sep 17 '24 20:09 notpeter

I like how sublime handles this. By allowing a selection border.

Screenshot 2024-09-19 at 7 45 14 PM

You can have a selection background color as well (I've made mine almost transparent). Or you can have a background color and no border.

Sublime also uses underline for read/write highlight

Screenshot 2024-09-19 at 7 46 54 PM

You can still have diagnostics

Screenshot 2024-09-19 at 7 53 22 PM

thataboy avatar Sep 20 '24 03:09 thataboy

Sublime has a really nice theming system indeed

juliangarnier avatar Sep 20 '24 10:09 juliangarnier

+1 on ability to create borders for selections

AlbertMarashi avatar Sep 23 '24 02:09 AlbertMarashi

+1 on ability to create borders for selections

WIP. I got something.

Screenshot 2024-09-24 at 1 04 45 PM

thataboy avatar Sep 24 '24 20:09 thataboy

Image Matches highlights super annoying in some case... Make background color fixable in theme and add another highlight layer on it is the best solution. Image

rainbowflesh avatar May 18 '25 18:05 rainbowflesh

please fix find/search and match highlighting on default themes. the 67% and 70% opacity difference (or whatever it actually is) makes search unusable for tracking which match is selected

exastone avatar May 26 '25 14:05 exastone

Search in Zed is so annoying, especially if you have eye vision problems.

andremacola avatar Jul 10 '25 12:07 andremacola

Any updates on this issue?. Im working on porting the Neovim Slate Theme to Zed beacause I really love that colorshceme.

My problem is the highlights don't work as well in Zed due to this issue.

cloudUser98 avatar Aug 04 '25 15:08 cloudUser98