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

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

Open
1 task done
juliangarnier opened this issue Sep 16, 2024 · 9 comments
Open
1 task done
Labels
accessibility Improvement related to color contrast, screen reader support, keyboard navigation, etc design papercut Small visual defect enhancement [core label] theme Feedback for theme configuration, accessibility, visual issues, etc

Comments

@juliangarnier
Copy link

juliangarnier commented Sep 16, 2024

Check for existing issues

  • 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 juliangarnier changed the title Expose more "foreground" and "background" color parameters to themes / UI [Accessibility] Low contrast / readability of matches, highlights, and selected text. Sep 17, 2024
@juliangarnier
Copy link
Author

juliangarnier commented Sep 17, 2024

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

@AlbertMarashi
Copy link
Contributor

AlbertMarashi commented Sep 17, 2024

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

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)

@juliangarnier
Copy link
Author

juliangarnier commented Sep 17, 2024

@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))",
}
hl.mp4
  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.

@notpeter notpeter added theme Feedback for theme configuration, accessibility, visual issues, etc accessibility Improvement related to color contrast, screen reader support, keyboard navigation, etc and removed triage labels Sep 17, 2024
@notpeter
Copy link
Member

See also:

@thataboy
Copy link
Contributor

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

@juliangarnier
Copy link
Author

Sublime has a really nice theming system indeed

@AlbertMarashi
Copy link
Contributor

+1 on ability to create borders for selections

@thataboy
Copy link
Contributor

+1 on ability to create borders for selections

WIP. I got something.

Screenshot 2024-09-24 at 1 04 45 PM

@marcospb19
Copy link
Contributor

My 2 cents on visibility: I can never see where my cursor is when I'm going through search matches.

image

Answer: cursor is on second "pane" match.

(It's harder when they're not adjacent.)

@notpeter notpeter added the design papercut Small visual defect label Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility Improvement related to color contrast, screen reader support, keyboard navigation, etc design papercut Small visual defect enhancement [core label] theme Feedback for theme configuration, accessibility, visual issues, etc
Projects
None yet
Development

No branches or pull requests

5 participants