From 7cd0e40039fc0ec9f3bd6b048e1be813040f2742 Mon Sep 17 00:00:00 2001 From: "Ayose C." Date: Wed, 29 Apr 2026 20:23:37 +0000 Subject: [PATCH] fix(lsp): fix threshold to compute contrast color #39504 Problem: The threshold to consider a color as bright is too high, and for some colors the foreground is set to white when it should be black. Solution: Change the threshold to 0.179. This value is taken from pastel-textcolor. --- runtime/lua/vim/lsp/document_color.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/lua/vim/lsp/document_color.lua b/runtime/lua/vim/lsp/document_color.lua index 3f99787fbc..734218ea94 100644 --- a/runtime/lua/vim/lsp/document_color.lua +++ b/runtime/lua/vim/lsp/document_color.lua @@ -45,7 +45,7 @@ local function get_contrast_color(color) -- Source: https://www.w3.org/TR/WCAG21/#dfn-relative-luminance -- Using power 2.2 is a close approximation to full piecewise transform local R, G, B = (r / 255) ^ 2.2, (g / 255) ^ 2.2, (b / 255) ^ 2.2 - local is_bright = (0.2126 * R + 0.7152 * G + 0.0722 * B) > 0.5 + local is_bright = (0.2126 * R + 0.7152 * G + 0.0722 * B) > 0.179 return is_bright and '#000000' or '#ffffff' end