branch: master
commit d82dc2c0d33f1cd4b74876af8f920c81a3636f4b
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
counsel.el (counsel-colors--best-contrast-color): Return same color on error
In case `color-name-to-rgb' returns nil.
Re #921
---
counsel.el | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/counsel.el b/counsel.el
index a2d3945..7ec3a7b 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2809,13 +2809,15 @@ midpoint, then the chosen color is black, otherwise is
white. This
helps to improve the contrast and readability of a text regardless of
the background color."
(let ((rgb (color-name-to-rgb color)))
- (if (>
- (+ (* (nth 0 rgb) 0.299)
- (* (nth 1 rgb) 0.587)
- (* (nth 2 rgb) 0.114))
- 0.5)
- "#000000"
- "#FFFFFF")))
+ (if rgb
+ (if (>
+ (+ (* (nth 0 rgb) 0.299)
+ (* (nth 1 rgb) 0.587)
+ (* (nth 2 rgb) 0.114))
+ 0.5)
+ "#000000"
+ "#FFFFFF")
+ color)))
(defun counsel-colors--update-highlight (cand)
"Update the highlight face for the current candidate CAND.