Home Download Buy Blog Forum Support

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

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

Postby ask on Sun Nov 13, 2011 12:25 am

So, do you actually switch out the theme file for just the CSS view or for all views? I have only skimmed the code. It would be nice if ST2 allowed access to the structure in memory so you didn't have to save a modified physical copy, but sadly I don't think that is available either.


I'm generating theme file only:
1. in css file
2. new colors are in file, otherwise just re-do add_regions

Hope is future ST releases, we will have richer API.

Hmm. Only get grey scale colors here. I may take a deeper look into it later.


Ugdate from github. I made some fixes. Hope they will help.
ask
 
Posts: 26
Joined: Wed Sep 14, 2011 12:40 pm

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

Postby facelessuser on Sun Nov 13, 2011 3:08 am

ask wrote:Hope is future ST releases, we will have richer API.

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

ask wrote:Update from github. I made some fixes. Hope they will help.

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.
Screen Shot 2011-11-12 at 9.41.42 PM.png
Screen Shot 2011-11-12 at 9.41.42 PM.png (11.65 KiB) Viewed 1489 times


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.
facelessuser
 
Posts: 1543
Joined: Tue Apr 05, 2011 7:38 pm

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

Postby ask on Sun Nov 13, 2011 5:29 am

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.
Last edited by ask on Sun Nov 13, 2011 12:32 pm, edited 1 time in total.
ask
 
Posts: 26
Joined: Wed Sep 14, 2011 12:40 pm

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

Postby Squirrel on Sun Nov 13, 2011 9:09 am

Thanks for this plugin, it works great.
Squirrel
 
Posts: 2
Joined: Sat Oct 01, 2011 4:11 am

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

Postby ask on Sun Nov 13, 2011 12:29 pm

You are welcome. Hope soon i can fix most noticeable bugs.
If you have any suggestions about this plugin, i'm ready to listen.
ask
 
Posts: 26
Joined: Wed Sep 14, 2011 12:40 pm

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

Postby facelessuser on Sun Nov 13, 2011 7:51 pm

ask wrote:ps: i would be grateful for any suggestions how to improve my code, because i'm not actually a programmer.


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: Select all
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: [Color], colors to colorize `regions`
    """

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


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.
facelessuser
 
Posts: 1543
Joined: Tue Apr 05, 2011 7:38 pm

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

Postby facelessuser on Sun Nov 13, 2011 10:39 pm

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.
facelessuser
 
Posts: 1543
Joined: Tue Apr 05, 2011 7:38 pm

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

Postby ask on Mon Nov 14, 2011 4:41 am

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.
ask
 
Posts: 26
Joined: Wed Sep 14, 2011 12:40 pm

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

Postby facelessuser on Mon Nov 14, 2011 6:26 am

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.
facelessuser
 
Posts: 1543
Joined: Tue Apr 05, 2011 7:38 pm

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

Postby ask on Mon Nov 14, 2011 10:54 am

facelessuser wrote: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.


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.
ask
 
Posts: 26
Joined: Wed Sep 14, 2011 12:40 pm

PreviousNext

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 7 guests