propogate the colours

This commit is contained in:
Gabriel Dinner-David 2024-12-19 23:39:43 -05:00
parent 68c52a2435
commit cc71969884
4 changed files with 23 additions and 5 deletions

View file

@ -21,7 +21,7 @@ use helix_view::{
document::{ColorSwatchesId, DocumentColorSwatches, DocumentInlayHints, DocumentInlayHintsId},
editor::Action,
handlers::lsp::SignatureHelpInvoked,
theme::Style,
theme::{Color, Style},
Document, View,
};
@ -1346,6 +1346,7 @@ fn compute_color_swatches_for_view(
// let mut padding_before_color_swatches = Vec::new();
let mut color_swatches = Vec::new();
let mut colors = Vec::new();
// let mut padding_after_color_swatches = Vec::new();
let doc_text = doc.text();
@ -1364,12 +1365,18 @@ fn compute_color_swatches_for_view(
let label = String::from("");
color_swatches.push(InlineAnnotation::new(char_idx, label));
colors.push(Color::Rgb(
(swatch.color.red * 255.) as u8,
(swatch.color.green * 255.) as u8,
(swatch.color.blue * 255.) as u8,
));
}
doc.set_color_swatches(
view_id,
DocumentColorSwatches {
id: new_doc_color_swatches_id,
colors,
color_swatches,
},
);

View file

@ -207,9 +207,10 @@ impl EditorView {
config.end_of_line_diagnostics,
));
if let Some(swatches) = doc.color_swatches(view.id) {
for swatch in swatches.color_swatches.clone() {
for (swatch, color) in swatches.color_swatches.iter().zip(swatches.colors.iter()) {
struct SwatchAnnotate {
swatch_idx: usize,
color: Color,
}
impl Decoration for SwatchAnnotate {
fn decorate_grapheme(
@ -218,14 +219,19 @@ impl EditorView {
_grapheme: &FormattedGrapheme,
style: &mut Style,
) -> usize {
style.fg = Some(Color::Rgb(4, 12, 28));
style.fg = Some(self.color);
usize::MAX
}
fn reset_pos(&mut self, _pos: usize) -> usize {
self.swatch_idx
fn reset_pos(&mut self, pos: usize) -> usize {
if self.swatch_idx >= pos {
self.swatch_idx
} else {
usize::MAX
}
}
}
decorations.add_decoration(SwatchAnnotate {
color: *color,
swatch_idx: swatch.char_idx,
});
}

View file

@ -38,6 +38,7 @@ use helix_core::{
ChangeSet, Diagnostic, LineEnding, Range, Rope, RopeBuilder, Selection, Syntax, Transaction,
};
use crate::theme::Color;
use crate::{
editor::Config,
events::{DocumentDidChange, SelectionDidChange},
@ -275,6 +276,7 @@ pub struct DocumentColorSwatches {
pub id: ColorSwatchesId,
pub color_swatches: Vec<InlineAnnotation>,
pub colors: Vec<Color>,
}
impl DocumentColorSwatches {
@ -283,6 +285,7 @@ impl DocumentColorSwatches {
Self {
id,
color_swatches: Vec::new(),
colors: Vec::new(),
}
}
}
@ -1472,6 +1475,7 @@ impl Document {
for text_annotation in self.color_swatches.values_mut() {
let DocumentColorSwatches {
id: _,
colors: _,
color_swatches,
} = text_annotation;

View file

@ -484,6 +484,7 @@ impl View {
};
if let Some(DocumentColorSwatches {
id: _,
colors: _,
color_swatches,
}) = doc.color_swatches.get(&self.id)
{