Search code examples
visual-studio

Text editor colors are subdued on Vistual Studio


The color of selected text (and in general) is darker than the settings.

I checked, and indeed the color is influenced by the settings, e.g., setting it to red, but it appears darker.

enter image description here

enter image description here


To explain my image. You see the "Options" dialog, where I set the color of the selected text to light blue (see the sample). Also, note that it's the system default, thus you can see the same background color of VS on the taskbar on the left.

Despite the setting, you can see that the selected text in the editor has a different, darker, color.

Not related to the image. I performed a sanity check, to see if setting the color in the dialog indeed makes a difference. I changed it to, e.g., red (again, not illustrated by the image), and indeed the background text in the editor was change to red, albeit a darker shade.


Solution

  • It's not a bug; it's working as designed.

    There, in the dialog, you are setting the opaque color for the background of selected/highlighted text. The color you set is being respected by Visual Studio.

    However, Visual Studio is overlaying your selected color on top of the selected text with partial transparency. This is why the color appears to be darker and more washed out. It's also why you cannot set the foreground color—because there is no fixed foreground color: it's contextually-aware.

    The reason Visual Studio does this is so that the foreground color (from coloring of various syntactical elements within the highlighted text) can be preserved, even when the text is selected.

    This has been the case for all versions of Visual Studio going back to 2010, when this feature was introduced:

    As you may have noticed, text selection in Visual Studio 2010 is a bit more colorful than in previous versions. In VS 2008 and earlier, selected text had a single foreground color and a single background color, usually white text on a navy blue background by default. However, we have made substantial changes and improvements to the Visual Studio Editor for this release, including the new for VS 2010 ability to compose different display layers together. One of the many benefits of this is that we can combine the background color for selection with the foreground colors for a variety of other display items (plain text, keywords, comments, etc.) to show syntax coloring not only for unselected text but now for selected text as well, which we think makes selected code easier to understand. Check out this side-by-side comparison to see the difference:

    Side-by-side comparison of text selection in Visual Studio 2008 vs. Visual Studio 2010.

    In light of this new mini-feature, we intentionally disabled the foreground color option for Selected Text in Tools->Options->Environment->Fonts and Colors. Because selected text doesn’t have a single foreground color but instead retains whatever syntax coloring it had when not selected, an option for selected text foreground color doesn’t make sense for Visual Studio 2010. For Beta2, the Tools->Options preview for Selected Text always shows the VS 2008-style white foreground color, which we realize can be confusing. We’ve already updated this internally so that for VS 2010 RTM, the Item Foreground Color dropdown and the Sample preview box will show your default Plain Text foreground color instead of white, giving you a more accurate idea of what selected text will look like in the editor.

    I don't think there is any built-in option to turn off the partial transparency of selected text. However, the underlying editor itself does support this, and there used to be extensions that would do it. For example, SelectionForeground by Noah Richards. This one is still on the Marketplace, but I don't know if it will work with modern versions of Visual Studio. It might, though, so go ahead and test it. If working correctly, it will result in an opaque background color being used, with a single, solid color for foreground text. If that one doesn't work with modern versions of Visual Studio, maybe you can search the Marketplace to find a more modern replacement. Or, perhaps you can use Noah's code to write your own.