Sublime Forum

[CSS, theme] use real colors to highlight colors props

#22

I hope so, too. I have to do some ugly things in Hex Viewer because the API can’t quite do what I need.

Much Better. It is recognizing color names now, and seems to be handling hex fine, for the most part. Sometimes I get weird issues where half the hex will be one color and the other half will be another; it seems to sometimes split the six char hex into two three char hex. RGB on the other hand doesn’t seem to be working to well, but I am sure it is just a matter of time before you get all of that working smoothly, I really think you got the hard part done. Really good progress. Keep it up.

I was just playing around with colors.

I actually suspect it is highlighting hex correctly but not always clearing old highlighting correctly. I believe in the picture above, it highlighted ff0 correctly, and then highlighted ff0000 correctly but they both still exist creating the weird looking split. I haven’t traced the issue in the code, but I would double check the clearing algorithm and possibly look for overlaps.

0 Likes

#23

Thanks for testing.
Yeah, i did’n clear old regions well.
I’m currently working on improving re-colorization.
Then test, test, and test once more _)
ps: i would be grateful for any suggestions how to improve my code, because i’m not actually a programmer.

0 Likes

#24

Thanks for this plugin, it works great.

0 Likes

#25

You are welcome. Hope soon i can fix most noticeable bugs.
If you have any suggestions about this plugin, i’m ready to listen.

0 Likes

#26

I found out your issue with RGB. You should only refer to your colors in hex throughout. Don’t save colors in theme as RGB, or color name; just hex. This is invalid in the theme file 255,255,0. The commas cause it to fail. RGB will not get colored. Be consistant. Since you are already converting everything to hex, let that be the way you save them all, and reference them all since it will work without issue in the theme file. Remove all of the other referencing. I have always found that simplicity makes my life easier in coding. The less things I have to keep track of, the better. I would even go as far to make sure to convert 3 char hex to 6 char hex (#3f3 -> #33ff33)

For example just changing these two functions below to only reference the color.hex portion allowed RGB, color names, and hex to work.

[code]def template(color):
“”“Template dict to use in color theme plist generating”""
el = {
‘name’: escape(color.hex),
‘scope’: color.hex,
‘settings’: {
‘background’: color.hex,
‘foreground’: color.opposite
}
}
return el

def colorize_regions(view, regions, colors):
“”"Colorize given regions through ST API.

Arguments:
regions: [sublime.Region], regions to colorize
colors: , colors to colorize `regions`
"""

regions_colors = zip(regions, colors)
for r, c  in regions_colors:
    view.add_regions(str(r), [r], c.hex)[/code]

I haven’t dug into how you are trying to manage re-colorization, but that is going to have to be looked into. I think at one time in testing, I had a rgb color highlighted in three overlapping colors.

**Edit: **I think I will make a pull request of the few things I have changed. I fix the RGB issue, I fixed the handling of your 3 sign hex. I might not get to it today, but I will let you know.

0 Likes

#27

I think I fixed the re-colorization issue as well. The key is to use very predictable names for region highlighting, so you can quickly clear them all before re-colorizing.

I issued a pull request with all of my current fixes.

0 Likes

#28

At first, thanks for advices. I really appreciate it.
Second, thanks you for digging into my code, I know how painful sometimes it can be.
I looked through your changes, the idea of naming regions is quite good.
And of course dozen of stupid bugs.
Merged.

0 Likes

#29

The whole naming the regions was actually out of necessity. I couldn’t clear some of the regions if the scope changed, but I could always clear a region if I knew its name. When editing a color, it looses its scope from time to time because you are removing characters. I tried to do delete the regions searching for the color scope as they were created, but it would miss the one that was being edited.

There is still one more issue I may try and track down. When editing a css color, it doesn’t always update or it updates too early (on RGB). Like if you are trying to enter 112 in the green channel, it will trigger on the 1 and ignore the 12.

0 Likes

#30

I found this bug. It was because of bugy optimization.
Now it always update colors and generate color theme only if necessary.
Pull from me.

0 Likes

#31

Cool. I will give it a try.

I actually find this plugin pretty useful. Thanks for the all the work on this.

0 Likes

#32

Just got around to trying it I think you must have made a change to writing the theme file.

Traceback (most recent call last): File "./sublime_plugin.py", line 143, in on_modified File "./css-colors.py", line 378, in on_modified File "./css-colors.py", line 306, in colorize_css File "./css-colors.py", line 261, in generate_color_theme File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plistlib.py", line 75, in readPlist pathOrFile = open(pathOrFile) IOError: [Errno 2] No such file or directory: u'/Users/facelessuser/Library/Application Support/Sublime Text 2/Packages/User/Colorized-766606182254614-Monokai Soda.tmTheme'

This causes the colors to all be white since it looks like it is failing to write the theme file.

0 Likes

#33

Hope last commit will fix this issue.
Before i delete previously colorized theme every time i apply new.
Now i do it only on init.

0 Likes

#34

I’ve got a fix comming. Hang tight for a pull request.

Your last commit fixed it, but I have a fix that cleans up extra files and fixes it.

0 Likes

#35

Pull requested. Now it works great! I will do some more testing in the next couple of days.

0 Likes

#36

why, #00 is white? I think this isn’t a good idea.

0 Likes

#37

It shouldn’t even catch such colors, since it’s not a valid hex color.

0 Likes

#38

wow, its working great so far! Thanks for your work.

0 Likes

#39

is it ready to use yet?

0 Likes

#40

The kind of coding I do for work is not web programming (we coding is more of a hobby for me), but from what limited testing I have been doing, I think it is safe to use.

There are a couple of items I think would be nice to have addressed before release though:

  • ** First:**
    The current commands available in the command palette are: css_colorize and css_uncolorize. I think they should be named using the common convention already used in the command palette: CSS Colors: Colorize and CSS Colors: Un-colorize. That way I can just use the name CSS Colors and find all available commands for the plugin.
  • Second:
    I think the colorize/uncolorize commands’ effects should be permanent. Currently if I invoke the uncolorize command, the effects only last until I edit a color, then everything becomes colorized again.
  • Third:
    Available in the menu under View is the menu item CSS dynamic highligting. This allows for a toggling of colorize/uncolorize that is permanent, but the menu item gives no indication of the current state of said toggling; it would be nice if there was some indication.
0 Likes

#41

Well i tried it and every time i enter a color, this pop up window appears with some error (check image in attachments)
After i press OK, it seems to show correctly but when i enter another color somewhere, again this error shows up, its pretty annoying :confused:
Any way to fix this?


0 Likes