From bba5669e154a241b6e13be8c09d59acf2d81bc22 Mon Sep 17 00:00:00 2001 From: Nik Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Mon, 24 Mar 2025 22:26:42 +0000 Subject: [PATCH 1/8] chore: store bytes as `rgb` instead of `bgr` --- helix-view/src/theme.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index af8f03bca..57016b3a7 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -300,7 +300,7 @@ impl Theme { /// Interpret a Highlight with the RGB foreground fn decode_rgb_highlight(rgb: usize) -> Option<(u8, u8, u8)> { (rgb > Self::RGB_START).then(|| { - let [b, g, r, ..] = rgb.to_ne_bytes(); + let [r, g, b, ..] = rgb.to_ne_bytes(); (r, g, b) }) } @@ -308,9 +308,9 @@ impl Theme { /// Create a Highlight that represents an RGB color pub fn rgb_highlight(r: u8, g: u8, b: u8) -> Highlight { Highlight(usize::from_ne_bytes([ - b, - g, r, + g, + b, u8::MAX, u8::MAX, u8::MAX, From 143bce26cbb7f7199bf291cad8c4fa8a6eac0e10 Mon Sep 17 00:00:00 2001 From: Nik Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Mon, 24 Mar 2025 22:27:32 +0000 Subject: [PATCH 2/8] fix: use `to_le_bytes` instead of `to_ne_bytes` --- helix-view/src/theme.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index 57016b3a7..aea6f60c6 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -300,14 +300,14 @@ impl Theme { /// Interpret a Highlight with the RGB foreground fn decode_rgb_highlight(rgb: usize) -> Option<(u8, u8, u8)> { (rgb > Self::RGB_START).then(|| { - let [r, g, b, ..] = rgb.to_ne_bytes(); + let [r, g, b, ..] = rgb.to_le_bytes(); (r, g, b) }) } /// Create a Highlight that represents an RGB color pub fn rgb_highlight(r: u8, g: u8, b: u8) -> Highlight { - Highlight(usize::from_ne_bytes([ + Highlight(usize::from_le_bytes([ r, g, b, From 683701221fd1b0a790aa5a0efcd70ec74489db67 Mon Sep 17 00:00:00 2001 From: Nik Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Mon, 24 Mar 2025 22:32:55 +0000 Subject: [PATCH 3/8] chore: use `to_be_bytes` representation --- helix-view/src/theme.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index aea6f60c6..e74baf771 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -300,22 +300,22 @@ impl Theme { /// Interpret a Highlight with the RGB foreground fn decode_rgb_highlight(rgb: usize) -> Option<(u8, u8, u8)> { (rgb > Self::RGB_START).then(|| { - let [r, g, b, ..] = rgb.to_le_bytes(); + let [.., r, g, b] = rgb.to_be_bytes(); (r, g, b) }) } /// Create a Highlight that represents an RGB color pub fn rgb_highlight(r: u8, g: u8, b: u8) -> Highlight { - Highlight(usize::from_le_bytes([ + Highlight(usize::from_be_bytes([ + u8::MAX, + u8::MAX, + u8::MAX, + u8::MAX, + u8::MAX, r, g, b, - u8::MAX, - u8::MAX, - u8::MAX, - u8::MAX, - u8::MAX, ])) } From b732be46935b82e85e9db6b57989d8f7b72671c8 Mon Sep 17 00:00:00 2001 From: Nik Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Tue, 25 Mar 2025 10:59:18 +0000 Subject: [PATCH 4/8] fix: decode_rgb_highlight works on 32-bit architectures --- helix-view/src/theme.rs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index e74baf771..7c04d7304 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -298,25 +298,18 @@ impl Theme { const RGB_START: usize = (usize::MAX << (8 + 8 + 8)) - 1; /// Interpret a Highlight with the RGB foreground - fn decode_rgb_highlight(rgb: usize) -> Option<(u8, u8, u8)> { - (rgb > Self::RGB_START).then(|| { + const fn decode_rgb_highlight(rgb: usize) -> Option<(u8, u8, u8)> { + if rgb > Self::RGB_START { let [.., r, g, b] = rgb.to_be_bytes(); - (r, g, b) - }) + Some((r, g, b)) + } else { + None + } } /// Create a Highlight that represents an RGB color - pub fn rgb_highlight(r: u8, g: u8, b: u8) -> Highlight { - Highlight(usize::from_be_bytes([ - u8::MAX, - u8::MAX, - u8::MAX, - u8::MAX, - u8::MAX, - r, - g, - b, - ])) + pub const fn rgb_highlight(r: u8, g: u8, b: u8) -> Highlight { + Highlight(Self::RGB_START + 1 + ((r as usize) << 16) + ((g as usize) << 8) + b as usize) } #[inline] From f6ef5e9d2b62ebc663662137ccb4f213c1f35d81 Mon Sep 17 00:00:00 2001 From: Nik Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Sat, 7 Jun 2025 10:56:36 +0100 Subject: [PATCH 5/8] chore: remove accidentally committed --- example.css | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 example.css diff --git a/example.css b/example.css deleted file mode 100644 index a1e97c609..000000000 --- a/example.css +++ /dev/null @@ -1,3 +0,0 @@ -body { - background-color: #ff0000; -} From d5f99b666cc4ea15f88b13fdd25cf595e379211a Mon Sep 17 00:00:00 2001 From: Nik Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Sat, 7 Jun 2025 11:03:46 +0100 Subject: [PATCH 6/8] fix: use BE representation instead of NE --- helix-view/src/theme.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index 330078c56..7ab5a4f2f 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -298,19 +298,18 @@ impl Theme { const RGB_START: u32 = (u32::MAX << (8 + 8 + 8)) - 1 - (u32::MAX - Highlight::MAX); /// Interpret a Highlight with the RGB foreground - const fn decode_rgb_highlight(rgb: Highlight) -> Option<(u8, u8, u8)> { - let rgb = rgb.get(); - if rgb > Self::RGB_START { - let [.., r, g, b] = rgb.to_be_bytes(); - Some((r, g, b)) - } else { - None - } + fn decode_rgb_highlight(highlight: Highlight) -> Option<(u8, u8, u8)> { + (highlight.get() > Self::RGB_START).then(|| { + let [r, g, b, ..] = (highlight.get() + 1).to_be_bytes(); + (r, g, b) + }) } /// Create a Highlight that represents an RGB color pub const fn rgb_highlight(r: u8, g: u8, b: u8) -> Highlight { - Highlight::new(Self::RGB_START + 1 + ((r as u32) << 16) + ((g as u32) << 8) + b as u32) + // -1 because highlight is "non-max": u32::MAX is reserved for the null pointer + // optimization. + Highlight::new(u32::from_be_bytes([r, g, b, u8::MAX]) - 1) } #[inline] From 94276ba2acb379988f1023d330ec6a1a465f1cd1 Mon Sep 17 00:00:00 2001 From: Nik Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Sat, 7 Jun 2025 11:19:23 +0100 Subject: [PATCH 7/8] fix: use big endian endian --- helix-view/src/theme.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index 7ab5a4f2f..b82fa3e30 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -300,7 +300,7 @@ impl Theme { /// Interpret a Highlight with the RGB foreground fn decode_rgb_highlight(highlight: Highlight) -> Option<(u8, u8, u8)> { (highlight.get() > Self::RGB_START).then(|| { - let [r, g, b, ..] = (highlight.get() + 1).to_be_bytes(); + let [.., r, g, b] = (highlight.get() + 1).to_be_bytes(); (r, g, b) }) } @@ -309,7 +309,7 @@ impl Theme { pub const fn rgb_highlight(r: u8, g: u8, b: u8) -> Highlight { // -1 because highlight is "non-max": u32::MAX is reserved for the null pointer // optimization. - Highlight::new(u32::from_be_bytes([r, g, b, u8::MAX]) - 1) + Highlight::new(u32::from_be_bytes([u8::MAX, r, g, b]) - 1) } #[inline] From d24381eff568ae78049d2285b812186aa3ba4400 Mon Sep 17 00:00:00 2001 From: Nik Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Sat, 7 Jun 2025 11:19:48 +0100 Subject: [PATCH 8/8] chore: remove `const` --- helix-view/src/theme.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-view/src/theme.rs b/helix-view/src/theme.rs index b82fa3e30..057c16622 100644 --- a/helix-view/src/theme.rs +++ b/helix-view/src/theme.rs @@ -306,7 +306,7 @@ impl Theme { } /// Create a Highlight that represents an RGB color - pub const fn rgb_highlight(r: u8, g: u8, b: u8) -> Highlight { + pub fn rgb_highlight(r: u8, g: u8, b: u8) -> Highlight { // -1 because highlight is "non-max": u32::MAX is reserved for the null pointer // optimization. Highlight::new(u32::from_be_bytes([u8::MAX, r, g, b]) - 1)