aboutsummaryrefslogtreecommitdiff
path: root/plugins/colorpreview.lua
diff options
context:
space:
mode:
authorLiqube <git@liqube.com>2020-05-18 20:57:17 +0200
committerLiqube <git@liqube.com>2020-05-18 20:57:17 +0200
commitfe3a8b17380e6ab007b645a3899109b799e5e731 (patch)
tree648b5d8f503f0eba206954927920deae3991790e /plugins/colorpreview.lua
parentd18469455b3969cb74a41b541745e6184cc61f15 (diff)
downloadlite-xl-plugins-fe3a8b17380e6ab007b645a3899109b799e5e731.tar.gz
lite-xl-plugins-fe3a8b17380e6ab007b645a3899109b799e5e731.zip
support #fff css format
Diffstat (limited to 'plugins/colorpreview.lua')
-rw-r--r--plugins/colorpreview.lua11
1 files changed, 9 insertions, 2 deletions
diff --git a/plugins/colorpreview.lua b/plugins/colorpreview.lua
index 2743f91..71f5c6d 100644
--- a/plugins/colorpreview.lua
+++ b/plugins/colorpreview.lua
@@ -7,7 +7,7 @@ local black = { common.color "#000000" }
local tmp = {}
-local function draw_color_previews(self, idx, x, y, ptn, base)
+local function draw_color_previews(self, idx, x, y, ptn, base, nibbles)
local text = self.doc.lines[idx]
local s, e = 0, 0
@@ -19,6 +19,13 @@ local function draw_color_previews(self, idx, x, y, ptn, base)
local r, g, b = str:match(ptn)
r, g, b = tonumber(r, base), tonumber(g, base), tonumber(b, base)
+ -- #123 becomes #112233
+ if nibbles then
+ r = r * 16
+ g = g * 16
+ b = b * 16
+ end
+
local x1 = x + self:get_col_x_offset(idx, s)
local x2 = x + self:get_col_x_offset(idx, e + 1)
local oy = self:get_line_text_y_offset()
@@ -41,6 +48,6 @@ local draw_line_text = DocView.draw_line_text
function DocView:draw_line_text(idx, x, y)
draw_line_text(self, idx, x, y)
draw_color_previews(self, idx, x, y, "#(%x%x)(%x%x)(%x%x)%f[%X]", 16)
+ draw_color_previews(self, idx, x, y, "#(%x)(%x)(%x)%f[%X]", 16, true) -- support #fff css format
draw_color_previews(self, idx, x, y, "rgba?%((%d+)%D+(%d+)%D+(%d+).-%)", 10)
end
-