Skip to content

Shortcut for opening color picker and insert color of selected format #52364

Closed

Description

@kasper9n

Problem

A huge dealbreaker for me is that VSCode just doesn't let me use the color picker ever, because I'm using Sass files. There does not seem to be any color picker extension that provides the functionality either, that isn't Windows-specific (I'm running macOS).

Feature request

I'd like the ability to spawn a color picker anywhere. So there would be a command that does exactly that, and when you're done it inserts the color code.

A nice inclusion would be if it could know if the cursor is in a color code, and accordingly update that color code. VSCode seems to do this only in a few file types now, which is a bummer for anyone not using those. I don't demand this, as long as I can get a color picker I'm content.

Activity

  1. justablob commented on Jul 19, 2018

    @justablob

    I'd love to see this feature aswell, +1.

  2. octref commented on Aug 6, 2018

    @octref
    Contributor

    I'm closing this as Sass do not have a language server, which is needed to support this feature.

    A simplified explanation as to how color picker works:

    • VS Code ask language server of a language X: "What's the colors in a document?"
    • LS responds with a list of code ranges that represent colors in the document
    • VS Code renders a color box (picker) next to the colors

    CSS/Less/Scss have language servers that can respond with color information properly. Sass doesn't have a LS to begin with.

  3. kasper9n commented on Aug 6, 2018

    @kasper9n
    ContributorAuthor

    Pine (@octref) That was not the main thing this is about. I want to spawn a color picker anywhere (using a shortcut), regardless of whether there's already a color code in the document or not.

  4. octref commented on Aug 6, 2018

    @octref
    Contributor

    @SpectralKH If you mean you want to spawn a color picker that doesn't have anything to do with the color code in a document, you can implement it as a Webview extension or look for existing extensions: https://marketplace.visualstudio.com/search?term=color%20picker&target=VSCode&category=All%20categories&sortBy=Relevance

  5. kasper9n commented on Aug 6, 2018

    @kasper9n
    ContributorAuthor

    Pine (@octref) None of the existing ones work for me (on macOS). This should be built-in and consistent between platforms.

  6. octref commented on Aug 6, 2018

    @octref
    Contributor

    If you mean you want this kind of color picker, but for Sass, see my response about Language Server above:

    image

    We have this component built-in, but we do not have resource to add support for each language so it shows this color picker component.

  7. kasper9n commented on Aug 6, 2018

    @kasper9n
    ContributorAuthor

    Pine (@octref) I want that color picker brought up by a shortcut anywhere.

  8. octref commented on Aug 6, 2018

    @octref
    Contributor

    You bring it up with a shortcut and pick a color, what do you expect to happen then?

  9. kasper9n commented on Aug 6, 2018

    @kasper9n
    ContributorAuthor

    Pine (@octref) I expect the popup from the image you shared to show up. Then I'd pick a color and press enter or something for the color code to be pasted in.

    To change the type of color code type (HEX, RGB, etc) to paste in, you could

    • Have the place that says "rgb(0, 0, 0)" be clickable, to toggle between color code types
    • Have the place that says "rgb(0, 0, 0)" be clickable, to open a drop-down menu with color code types.
    • Have a bar with different buttons like this:
      unnamed
  10. 60 remaining items

  11. Kwaadpepper commented on May 25, 2022

    @Kwaadpepper

    Found not way to spawn color picker in PHP files, someone managed to do this ?

    Yes. See #52364 (comment).

    Never mind just saw I has to add the php language into the extension parameter to supported languages.

      "vscode-color-picker.languages": [
          "php",
          "json",
          "python",
          "javascript",
          "typescript"
        ]
    
  12. georgefst commented on Apr 19, 2023

    @georgefst

    If #178242 is limited to CSS-formatted colours, that's kind of disappointing. Just because most popular languages have so much ceremony around using custom datatypes that everyone prefers to use strings for everything, doesn't mean the rest of us should suffer!

    At the very least, is there a reason why the last line of the screenshot doesn't seem to trigger the color picker? If rgb(r, g, b) weren't required to be in quotes, then the functionality could be used in most languages by defining a suitable rgb function (e.g. in Haskell, rgb(r,g,b) = RGBA r g b maxBound, though I'd have to disable my formatter at every use site to avoid a space between b and ().

  13. aiday-mar commented on Apr 19, 2023

    @aiday-mar
    Contributor

    Hi, George Thomas (@georgefst), thanks for your comment.

    The standalone color picker works for other language formats provided you have an extension installed that defines a DocumentColorProvider. The demo in the video, shows the default behavior when no marketplace extensions are installed, so that the user can still use the color picker when no DocumentColorProviders are present. The default is the CSS format. You may search in the marketplace for extensions that provide color functionality for the language of your choice.

    The last line does not trigger a color, because there is no color present there. The PR essentially added a default DocumentColorProvider, which detects if there is a CSS color at the cursor position, and initializes the color picker with that color. If no color is detected, the default RGB(0,0,0,1) is chosen.

    The value rgb(r, g, b) does not have to be in quotes when using the default provider. The only reason it is in quotes inside of the video is so that the compiler does not throw errors. As well as that the provider works even if there is a space between the values r, g and b, so there is no need to format.

  14. added
    insiders-releasedPatch has been released in VS Code Insiders
    and removed
    unreleasedPatch has not yet been released in VS Code Insiders
    on Apr 20, 2023
  15. georgefst commented on Apr 22, 2023

    @georgefst

    Ok cool, that's much more promising than I expected, thanks! I might have to try writing a colour provider extension for more idiomatic Haskell syntax, but it sounds like the "default" CSS one will be usable.

  16. locked and limited conversation to collaborators on Jun 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

editor-color-pickerEditor color picker widget issuesfeature-requestRequest for new features or functionalityhelp wantedIssues identified as good community contribution opportunitiesinsiders-releasedPatch has been released in VS Code Insiderson-testplan

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions