From d120a3574036a82062894108ee772b5536fc17bb Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Mon, 23 Dec 2024 13:57:52 +0000 Subject: [PATCH] feat: use padding for color swatches --- helix-term/src/commands/lsp.rs | 6 ++++-- helix-view/src/document.rs | 4 ++++ helix-view/src/view.rs | 9 ++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index cc585e82..6d60a7f7 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -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, }, ); diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 8bccd22c..d8005c6d 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -283,6 +283,7 @@ pub struct DocumentColorSwatches { pub id: ColorSwatchesId, pub color_swatches: Vec, + pub color_swatches_padding: Vec, pub colors: Vec, } @@ -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 { diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index 67d3ac66..a30ce5be 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -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);