Re: [code] [textadept] Bug: #RRGGBB notation does not work with set_sel_back

From: Mitchell <m.att.foicica.com>
Date: Mon, 18 Aug 2014 14:34:01 -0400 (Eastern Daylight Time)

Hi Joshua,

On Mon, 18 Aug 2014, Joshua Krmer wrote:

> Hi Mitchell,
>
> it seems there is a bug with the #RRGGBB colour notation in theme
> files. If the corresponding colour is defined in #RRGGBB notation, the
> selection background is rendered black. For example, I have changed
> line 15 in light.lua to the following:
>
> property['color.light_grey'] = '#ff0000'
>
> The selection background should be rendered red, but it is black.

The '#RRGGBB' notation can only be used for lexer colors, not for
Scintilla colors. You'll see on line 97 that '#ff0000' would be passed to
`buffer:set_sel_back()`, but the API documentation for that function
states the parameter must be a number in "0xBBGGRR" format. Since your
color isn't a number, it is interpreted as 0 (black).

One solution would be to change the "property_int()" to a function of your
own that transforms colors. For example (untested):

   local function convert_color(prop)
     local color = buffer.property[prop]
     if type(color) == 'number' then return color end
     local r, g, b = color:match('^#(%d%d)(%d%d)(%d%d)$')
     if r and g and b then
       return tonumber(b..g..r, 16)
     else
       return 0
     end
   end

   ...

   buffer:set_sel_back(true, convert_color(property['color.light_grey']))

Cheers,
Mitchell

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Mon 18 Aug 2014 - 14:34:01 EDT

This archive was generated by hypermail 2.2.0 : Tue 19 Aug 2014 - 06:49:18 EDT