mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-30 14:17:02 +00:00
Add whitespaces rendering
This commit is contained in:
parent
2d8c88ad73
commit
714734d279
2 changed files with 42 additions and 33 deletions
|
@ -889,39 +889,38 @@ impl EditorElement {
|
||||||
ShowInvisibles::None => {}
|
ShowInvisibles::None => {}
|
||||||
ShowInvisibles::All => {
|
ShowInvisibles::All => {
|
||||||
for invisible in &line_with_invisibles.invisibles {
|
for invisible in &line_with_invisibles.invisibles {
|
||||||
match invisible {
|
// TODO kb cache, deduplicate
|
||||||
Invisible::Tab { line_start_offset } => {
|
let (token_offset, mut test_svg) = match invisible {
|
||||||
// TODO kb cache, deduplicate
|
Invisible::Tab { line_start_offset } => (
|
||||||
let x_offset =
|
*line_start_offset,
|
||||||
line_with_invisibles.line.x_for_index(*line_start_offset);
|
Svg::new("icons/arrow_right_16.svg")
|
||||||
let font_size = line_with_invisibles.line.font_size();
|
.with_color(self.style.line_number),
|
||||||
let max_size = vec2f(font_size, font_size);
|
),
|
||||||
let origin = content_origin
|
Invisible::Whitespace { line_offset } => (
|
||||||
+ vec2f(
|
*line_offset,
|
||||||
-scroll_left + x_offset,
|
Svg::new("icons/plus_8.svg").with_color(self.style.line_number),
|
||||||
row as f32 * layout.position_map.line_height
|
),
|
||||||
- scroll_top,
|
};
|
||||||
);
|
|
||||||
|
|
||||||
let mut test_svg = Svg::new("icons/arrow_right_16.svg")
|
let x_offset = line_with_invisibles.line.x_for_index(token_offset);
|
||||||
.with_color(Color::red());
|
let font_size = line_with_invisibles.line.font_size();
|
||||||
let (_, mut layout_state) = test_svg.layout(
|
let max_size = vec2f(font_size, font_size);
|
||||||
SizeConstraint::new(origin, max_size),
|
let origin = content_origin
|
||||||
editor,
|
+ vec2f(
|
||||||
cx,
|
-scroll_left + x_offset,
|
||||||
);
|
row as f32 * layout.position_map.line_height - scroll_top,
|
||||||
test_svg.paint(
|
);
|
||||||
scene,
|
|
||||||
RectF::new(origin, max_size),
|
let (_, mut layout_state) =
|
||||||
visible_bounds,
|
test_svg.layout(SizeConstraint::new(origin, max_size), editor, cx);
|
||||||
&mut layout_state,
|
test_svg.paint(
|
||||||
editor,
|
scene,
|
||||||
cx,
|
RectF::new(origin, max_size),
|
||||||
);
|
visible_bounds,
|
||||||
}
|
&mut layout_state,
|
||||||
// TODO kb draw whitespaces too
|
editor,
|
||||||
Invisible::Whitespace { .. } => {}
|
cx,
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1723,6 +1722,16 @@ fn layout_highlighted_chunks<'a>(
|
||||||
invisibles.push(Invisible::Tab {
|
invisibles.push(Invisible::Tab {
|
||||||
line_start_offset: line.len(),
|
line_start_offset: line.len(),
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
invisibles.extend(
|
||||||
|
line_chunk
|
||||||
|
.chars()
|
||||||
|
.enumerate()
|
||||||
|
.filter(|(_, line_char)| line_char.is_whitespace())
|
||||||
|
.map(|(whitespace_index, _)| Invisible::Whitespace {
|
||||||
|
line_offset: line.len() + whitespace_index,
|
||||||
|
}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
line.push_str(line_chunk);
|
line.push_str(line_chunk);
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,7 +214,7 @@ pub struct Glyph {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Invisible {
|
pub enum Invisible {
|
||||||
Tab { line_start_offset: usize },
|
Tab { line_start_offset: usize },
|
||||||
Whitespace { line_range: std::ops::Range<usize> },
|
Whitespace { line_offset: usize },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Line {
|
impl Line {
|
||||||
|
|
Loading…
Reference in a new issue