Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 30eca3f

Browse files
committed
Add shorthand hex recognition
1 parent a94dc44 commit 30eca3f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lua/color-picker/utils/window.lua

+8-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ end --}}}
567567
-------------------------------------
568568

569569
local function detect_colors(str) --{{{
570-
local hex_pattern = "#%x%x%x%x%x%x%x?%x?"
570+
local hex_pattern = "#%x%x%x%x?%x?%x?%x?%x?"
571571
local rgb_pattern = "rgba?%(%s*%d+%s*,%s*%d+%s*,%s*%d+%s*.*%)"
572572
local hsl_pattern = "hsla?%(%s*%d+%s*,%s*%d+%s*%%*,%s*%d+%s*%%*.*%)"
573573

@@ -633,13 +633,15 @@ end --}}}
633633
local function sandwich_processor(str) --{{{
634634
local hex_capture_pattern = "#(%x%x%x%x%x%x)"
635635
local hexa_capture_pattern = "#(%x%x%x%x%x%x)(%x%x)"
636+
local short_hex_capture_pattern = "#(%x%x%x)"
636637
local rgba_capture_pattern = "rgba%(%s*(%d+)%s*,%s*(%d+)%s*,%s*(%d+)%s*,?%s*(%d+%.?%d*)%s*%)"
637638
local hsla_capture_pattern = "hsla%(%s*(%d+)%s*,%s*(%d+)%s*%%*,%s*(%d+)%s*%%,?%s*(%d+%.?%d*)%s*%)"
638639
local rgb_capture_pattern = "rgb%(%s*(%d+)%s*,%s*(%d+)%s*,%s*(%d+)%s*,?%s*%)"
639640
local hsl_capture_pattern = "hsl%(%s*(%d+)%s*,%s*(%d+)%s*%%*,%s*(%d+)%s*%%,?%s*%)"
640641

641642
local _, _, hex_val, hex_trans = string.find(str, hexa_capture_pattern)
642643
local _, _, hex = string.find(str, hex_capture_pattern)
644+
local _, _, short_hex = string.find(str, short_hex_capture_pattern)
643645
local _, _, ra, ga, ba, rgba = string.find(str, rgba_capture_pattern)
644646
local _, _, ha, sa, la, hsla = string.find(str, hsla_capture_pattern)
645647
local _, _, r, g, b = string.find(str, rgb_capture_pattern)
@@ -648,6 +650,11 @@ local function sandwich_processor(str) --{{{
648650
return { "hex", hex_val, hex_trans }
649651
elseif hex then
650652
return { "hex", hex }
653+
elseif short_hex then
654+
local red = short_hex:sub(1, 1)
655+
local green = short_hex:sub(2, 2)
656+
local blue = short_hex:sub(3, 3)
657+
return { "hex", red .. red .. green .. green .. blue .. blue }
651658
elseif ra then
652659
return { "rgb", tonumber(ra), tonumber(ga), tonumber(ba), tonumber(rgba) }
653660
elseif ha then

0 commit comments

Comments
 (0)