Skip to content

Text selection highlight is not shown on decorations w/background colors #75642

Closed

Description

Version: 1.35.1 (user setup)
Commit: c7d83e5
Date: 2019-06-12T14:30:02.622Z
Electron: 3.1.8
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Windows_NT x64 10.0.18362

If a decoration is set and includes a background color, selection highlight is not rendered.

In the following image, text decorations (with a background value) exist on the keywords and symbols, but not the whitespace. The entire section is selected. Notice that the whitespace receives a selection highlight color, but the decorated text does not.

image

Activity

  1. Tyriar commented on Jun 20, 2019

    @Tyriar
    Contributor
  2. added
    *duplicate
    on Jun 20, 2019
  3. Colengms commented on Jun 20, 2019

    @Colengms
    ContributorAuthor

    Daniel Imms (@Tyriar) , This was duped incorrectly. The cpptools issue should be duped to this, not vice version. (I work on cpptools). The issue is, generally, that if there is a background color specified on a TextEditorDecoration, no highlight selection color will be applied to it when that text is selected. We can work around the issue in cpptools when the desired background color happens to be the same as the editor background color (so, setting a background color is unnecessary, and avoided). But, the issue remains in the general case. Please apply selection highlight color on TextEditorDecorations when they have a background color specified, and their text is selected.

  4. Colengms commented on Jun 20, 2019

    @Colengms
    ContributorAuthor

    image

  5. Tyriar commented on Jun 20, 2019

    @Tyriar
    Contributor

    Colen Garoutte-Carson (@Colengms) ah sorry I thought it was just a limitation of how you did semantic coloring but it I've also seen this issue in the git diff decorations:

    Screen Shot 2019-06-20 at 2 31 10 PM

  6. removed
    *duplicate
    on Jun 20, 2019
  7. alexdima commented on Aug 5, 2019

    @alexdima
    Member

    This is as designed. Using a color with opacity 100% will result in other things not being visible. The solution is to use a color with an opacity < 100%.

  8. Tyriar commented on Aug 5, 2019

    @Tyriar
    Contributor
  9. Colengms commented on Aug 5, 2019

    @Colengms
    ContributorAuthor

    I'm almost certain this should not have been closed. The proposed solution does not work. Setting the (only available) "opacity" property of DecorationRenderOptions to 0.5, for example, has no effect on the visibility of the text selection highlight. As you can see, both the selected and unselected text (w/ red background) in the example below appear the same, despite opacity 0.5 being used.

    image

    Using an alpha channel value in the background color itself does not appear to be accepted.

    The opacity property would seem to only apply to the foreground color. Setting the editor background to another color, for example, I can see that the decoration's background color is not blended with it at all.

    image

    Furthermore, even if this worked, it would not be a good design to require that anyone who sets a background color on a decoration to use (at this point ambiguous) semi-transparency in order to avoid an issue that would cause user text selection not to be apparent when selecting text within the decoration. The text selection color should either be blended/inversed with the background color, or replace the background color, so that selection is apparent.

  10. alexdima commented on Aug 6, 2019

    @alexdima
    Member

    I am seeing something strange. I am seeing different results running from source or running from a built version at the same commit. I am using the following to reproduce:

    • package.json:
    {
        "name": "75642",
        "publisher": "alex",
        "version": "1.0.0",
        "engines": {
            "vscode": "^1.31.0"
        },
        "activationEvents": ["*"],
        "main": "index.js"
    }
    • index.js:
    const vscode = require('vscode');
    
    exports.activate = function() {
        const transparentRed = vscode.window.createTextEditorDecorationType({
            backgroundColor: '#ff000033'
        });
        const red = vscode.window.createTextEditorDecorationType({
            backgroundColor: '#ff0000ff'
        });
    
        const decorate = function() {
            const editor = vscode.window.activeTextEditor;
            if (!editor) {
                return;
            }
            editor.setDecorations(transparentRed, [new vscode.Range(215681, 0, 215681, 6)]);
            editor.setDecorations(red, [new vscode.Range(215683, 2, 215683, 7)]);
        }
        vscode.window.onDidChangeActiveTextEditor(decorate);
        decorate();
    };

    running from source

    image
    image

    running from a built version

    image
    image

  11. alexdima commented on Aug 6, 2019

    @alexdima
    Member

    Well, after debugging I can no longer reproduce this in the built version...

  12. alexdima commented on Aug 6, 2019

    @alexdima
    Member

    Ok, now I understand this weirdness, I am running into a code cache bug. I've created #78542 to track that.

    In any case, going back to our issue. I can set an opacity and it is respected. See the above sample code:
    image
    image

  13. locked and limited conversation to collaborators on Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions