microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.82k stars 29.5k forks source link

Color picker immediately closes on click (not allowing cycling through presentations or changing opacity) when a presentation has additionalTextEdits #136965

Closed DanTup closed 11 months ago

DanTup commented 3 years ago

When a ColorProvider provides multiple ColorPresentations, they can be cycled by clicking on the text in the color picker because dragging the color selector around does not close the color picker:

color_good

However, if the ColorPresentation contains additionaTextEdits, the color picker closes immediately upon clicking anywhere, making it impossible to select any other presentation. Clicking where you'd normally cycle through the presentations also immediately closes the picker.

color_bad

Here's an example. Paste this into a newly created VS Code extension, change activationEvents to * and then open a file with at least a few lines.

const colorRange = new vscode.Range(new vscode.Position(5, 0), new vscode.Position(5, 1));
const otherEditRange = new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0));
context.subscriptions.push(vscode.languages.registerColorProvider({ scheme: 'file' }, {
    provideDocumentColors(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.ProviderResult<vscode.ColorInformation[]> {
        return [
            new vscode.ColorInformation(
                colorRange,
                new vscode.Color(1, 0, 0, 1),
            ),
        ];
    },

    provideColorPresentations(color: vscode.Color, context: { document: vscode.TextDocument, range: vscode.Range }, token: vscode.CancellationToken): vscode.ProviderResult<vscode.ColorPresentation[]> {
        const one = new vscode.ColorPresentation('one');
        one.textEdit = new vscode.TextEdit(colorRange, one.label);
        one.additionalTextEdits = [
            new vscode.TextEdit(otherEditRange, 'IMPORT')
        ];
        const two = new vscode.ColorPresentation('two');
        two.textEdit = new vscode.TextEdit(colorRange, two.label);
        two.additionalTextEdits = [
            new vscode.TextEdit(otherEditRange, 'IMPORT')
        ];
        return [
            one,
            two,
        ];
    }
}));
rajhlinux commented 2 years ago

I have this same problem, its super annoying.

ezgif com-gif-maker

Whenever I put my mouse on the tiny color box, the color palette opens and when I hover the mouse to select a color, the entire color palette disappears.

I need to keep on repeating the above steps until the color palette does not close anymore.

Whats the fix to this issue? How can I use a color picker from an extension plugin?

Thanks.

gonzalologorg commented 1 year ago

Can confirm in vscode insiders it has been fixed

aiday-mar commented 1 year ago

Thanks for picking up on it @gonzalologorg, this issue will be closed

DanTup commented 1 year ago

This doesn't seem fixed in Insiders to me. Using the same code provided in my OP above. If anything, it seems to close more aggressively (sometimes just clicking on the colour block toggles it open and closed very quickly):

https://github.com/microsoft/vscode/assets/1078012/115e4fca-6042-4f41-a0d0-a1799a057854

Version: 1.85.0-insider (user setup)
Commit: 05cd2640ec8a106a4ee99cb38e6ee34fbec04f11
Date: 2023-11-21T05:35:09.651Z
Electron: 25.9.4
ElectronBuildId: 25127168
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Windows_NT x64 10.0.22621
aiday-mar commented 1 year ago

I see, apologies, I will reopen the issue

pooYAYooq commented 11 months ago

So frustrating, I have the same issue with my vs code.

screenspaceio commented 11 months ago

Same here. Started closing on click about a month ago.

DarkPromo commented 11 months ago

same here it is very annoyng. has any1 found a way to fix it<

peachtrees13 commented 11 months ago

Facing the same issue

spikethea commented 11 months ago

Got the same problem

starball5 commented 11 months ago

@aiday-mar thanks! what's the release milestone for the fix?

aiday-mar commented 11 months ago

Hey @starball5 this fix will go into Insiders soon, and then it will land in stable only end of January, which is when our next stable release is.

DanTup commented 11 months ago

@aiday-mar the colour picker stays open now, but it's not updating the range correctly, it's just inserting on every click.

Let me know if I should file a new issue about this (it's not really the same bug, but I suspect it might occur as a result of this fix):

https://github.com/microsoft/vscode/assets/1078012/0eed2879-fca2-463f-af1b-240d26db3bf3

I'm using the same code I posted above to repro.

aiday-mar commented 11 months ago

Hi @DanTup thank you for posting about this and apologies, it looks like the fix has caused a regression. Yes if you could please open an issue that would be great.

DanTup commented 11 months ago

I've opened https://github.com/microsoft/vscode/issues/200569