hack the text_decorations to make this work
This commit is contained in:
parent
9185448259
commit
68c52a2435
4 changed files with 39 additions and 5 deletions
|
@ -216,7 +216,8 @@ pub fn render_text(
|
|||
.unwrap_or((Style::default(), usize::MAX));
|
||||
}
|
||||
|
||||
let grapheme_style = if let GraphemeSource::VirtualText { highlight } = grapheme.source {
|
||||
let mut grapheme_style = if let GraphemeSource::VirtualText { highlight } = grapheme.source
|
||||
{
|
||||
let mut style = renderer.text_style;
|
||||
if let Some(highlight) = highlight {
|
||||
style = style.patch(theme.highlight(highlight.0));
|
||||
|
@ -231,7 +232,7 @@ pub fn render_text(
|
|||
overlay_style: overlay_style_span.0,
|
||||
}
|
||||
};
|
||||
decorations.decorate_grapheme(renderer, &grapheme);
|
||||
decorations.decorate_grapheme(renderer, &grapheme, &mut grapheme_style.syntax_style);
|
||||
|
||||
let virt = grapheme.is_virtual();
|
||||
let grapheme_width = renderer.draw_grapheme(
|
||||
|
|
|
@ -15,6 +15,7 @@ use crate::{
|
|||
|
||||
use helix_core::{
|
||||
diagnostic::NumberOrString,
|
||||
doc_formatter::FormattedGrapheme,
|
||||
graphemes::{next_grapheme_boundary, prev_grapheme_boundary},
|
||||
movement::Direction,
|
||||
syntax::{self, HighlightEvent},
|
||||
|
@ -205,6 +206,30 @@ impl EditorView {
|
|||
inline_diagnostic_config,
|
||||
config.end_of_line_diagnostics,
|
||||
));
|
||||
if let Some(swatches) = doc.color_swatches(view.id) {
|
||||
for swatch in swatches.color_swatches.clone() {
|
||||
struct SwatchAnnotate {
|
||||
swatch_idx: usize,
|
||||
}
|
||||
impl Decoration for SwatchAnnotate {
|
||||
fn decorate_grapheme(
|
||||
&mut self,
|
||||
_renderer: &mut TextRenderer,
|
||||
_grapheme: &FormattedGrapheme,
|
||||
style: &mut Style,
|
||||
) -> usize {
|
||||
style.fg = Some(Color::Rgb(4, 12, 28));
|
||||
usize::MAX
|
||||
}
|
||||
fn reset_pos(&mut self, _pos: usize) -> usize {
|
||||
self.swatch_idx
|
||||
}
|
||||
}
|
||||
decorations.add_decoration(SwatchAnnotate {
|
||||
swatch_idx: swatch.char_idx,
|
||||
});
|
||||
}
|
||||
}
|
||||
render_document(
|
||||
surface,
|
||||
inner,
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::cmp::Ordering;
|
|||
|
||||
use helix_core::doc_formatter::FormattedGrapheme;
|
||||
use helix_core::Position;
|
||||
use helix_view::editor::CursorCache;
|
||||
use helix_view::{editor::CursorCache, theme::Style};
|
||||
|
||||
use crate::ui::document::{LinePos, TextRenderer};
|
||||
|
||||
|
@ -81,6 +81,7 @@ pub trait Decoration {
|
|||
&mut self,
|
||||
_renderer: &mut TextRenderer,
|
||||
_grapheme: &FormattedGrapheme,
|
||||
_style: &mut Style,
|
||||
) -> usize {
|
||||
usize::MAX
|
||||
}
|
||||
|
@ -108,7 +109,12 @@ impl<'a> DecorationManager<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn decorate_grapheme(&mut self, renderer: &mut TextRenderer, grapheme: &FormattedGrapheme) {
|
||||
pub fn decorate_grapheme(
|
||||
&mut self,
|
||||
renderer: &mut TextRenderer,
|
||||
grapheme: &FormattedGrapheme,
|
||||
style: &mut Style,
|
||||
) {
|
||||
for (decoration, hook_char_idx) in &mut self.decorations {
|
||||
loop {
|
||||
match (*hook_char_idx).cmp(&grapheme.char_idx) {
|
||||
|
@ -117,7 +123,7 @@ impl<'a> DecorationManager<'a> {
|
|||
*hook_char_idx = decoration.skip_concealed_anchor(grapheme.char_idx)
|
||||
}
|
||||
Ordering::Equal => {
|
||||
*hook_char_idx = decoration.decorate_grapheme(renderer, grapheme)
|
||||
*hook_char_idx = decoration.decorate_grapheme(renderer, grapheme, style)
|
||||
}
|
||||
Ordering::Greater => break,
|
||||
}
|
||||
|
@ -163,6 +169,7 @@ impl Decoration for Cursor<'_> {
|
|||
&mut self,
|
||||
renderer: &mut TextRenderer,
|
||||
grapheme: &FormattedGrapheme,
|
||||
_style: &mut Style,
|
||||
) -> usize {
|
||||
if renderer.column_in_bounds(grapheme.visual_pos.col, grapheme.width())
|
||||
&& renderer.offset.row < grapheme.visual_pos.row
|
||||
|
|
|
@ -307,6 +307,7 @@ impl Decoration for InlineDiagnostics<'_> {
|
|||
&mut self,
|
||||
renderer: &mut TextRenderer,
|
||||
grapheme: &FormattedGrapheme,
|
||||
_style: &mut Style,
|
||||
) -> usize {
|
||||
self.state
|
||||
.proccess_anchor(grapheme, renderer.viewport.width, renderer.offset.col)
|
||||
|
|
Loading…
Add table
Reference in a new issue