feat: use padding for color swatches

This commit is contained in:
Nikita Revenco 2024-12-23 13:57:52 +00:00
parent ca5c96b982
commit d120a35740
3 changed files with 12 additions and 7 deletions

View file

@ -1479,7 +1479,7 @@ fn compute_color_swatches_for_view(
swatches.sort_by_key(|inlay_hint| inlay_hint.range.start);
let mut color_swatches = Vec::with_capacity(swatches.len());
// let mut color_swatches_padding = Vec::with_capacity(swatches.len());
let mut color_swatches_padding = Vec::with_capacity(swatches.len());
let mut colors = Vec::with_capacity(swatches.len());
let doc_text = doc.text();
@ -1492,7 +1492,8 @@ fn compute_color_swatches_for_view(
continue;
};
color_swatches.push(InlineAnnotation::new(swatch_index, ""));
color_swatches.push(InlineAnnotation::new(swatch_index, ""));
color_swatches_padding.push(InlineAnnotation::new(swatch_index, " "));
colors.push(Color::Rgb(
(swatch.color.red * 255.) as u8,
(swatch.color.green * 255.) as u8,
@ -1506,6 +1507,7 @@ fn compute_color_swatches_for_view(
id: new_doc_color_swatches_id,
colors,
color_swatches,
color_swatches_padding,
},
);

View file

@ -283,6 +283,7 @@ pub struct DocumentColorSwatches {
pub id: ColorSwatchesId,
pub color_swatches: Vec<InlineAnnotation>,
pub color_swatches_padding: Vec<InlineAnnotation>,
pub colors: Vec<Color>,
}
@ -292,6 +293,7 @@ impl DocumentColorSwatches {
Self {
id,
color_swatches: Vec::new(),
color_swatches_padding: Vec::new(),
colors: Vec::new(),
}
}
@ -1470,9 +1472,11 @@ impl Document {
id: _,
colors: _,
color_swatches,
color_swatches_padding,
} = text_annotation;
apply_inlay_hint_changes(color_swatches);
apply_inlay_hint_changes(color_swatches_padding);
}
helix_event::dispatch(DocumentDidChange {

View file

@ -485,13 +485,12 @@ impl View {
id: _,
colors: _,
color_swatches,
color_swatches_padding,
}) = doc.color_swatches.get(&self.id)
{
let type_style = theme
.and_then(|t| t.find_scope_index("ui.background"))
.map(Highlight);
text_annotations.add_inline_annotations(color_swatches, type_style);
text_annotations
.add_inline_annotations(color_swatches, None)
.add_inline_annotations(color_swatches_padding, None);
};
let config = doc.config.load();
let width = self.inner_width(doc);