fix zalgotext highlight
This commit is contained in:
@@ -46,8 +46,9 @@ impl Widget for TextEdit {
|
||||
fn draw(&mut self, painter: &mut Painter) {
|
||||
let base = painter.layer;
|
||||
painter.child_layer();
|
||||
let region = self.view.draw(painter);
|
||||
self.view.draw(painter);
|
||||
painter.layer = base;
|
||||
let region = self.region();
|
||||
|
||||
let size = vec2(1, self.attrs.line_height);
|
||||
match self.selection {
|
||||
@@ -62,7 +63,8 @@ impl Widget for TextEdit {
|
||||
}
|
||||
TextSelection::Span { start, end } => {
|
||||
let (start, end) = sort_cursors(start, end);
|
||||
for (top_left, width) in iter_layout_lines(start, end, &self.buf) {
|
||||
for (l, x, width) in iter_layout_lines(start, end, &self.buf) {
|
||||
let top_left = vec2(x, self.attrs.line_height * l as f32);
|
||||
painter.primitive_within(
|
||||
RectPrimitive::color(Color::SKY),
|
||||
size.with_x(width)
|
||||
@@ -97,34 +99,34 @@ fn iter_layout_lines(
|
||||
start: Cursor,
|
||||
end: Cursor,
|
||||
buf: &TextBuffer,
|
||||
) -> impl Iterator<Item = (Vec2, f32)> {
|
||||
) -> impl Iterator<Item = (usize, f32, f32)> {
|
||||
gen move {
|
||||
let mut iter = buf.layout_runs();
|
||||
for line in iter.by_ref() {
|
||||
let mut iter = buf.layout_runs().enumerate();
|
||||
for (i, line) in iter.by_ref() {
|
||||
if line.line_i == start.line
|
||||
&& let Some(start_x) = index_x(&line, start.index)
|
||||
{
|
||||
if start.line == end.line
|
||||
&& let Some(end_x) = index_x(&line, end.index)
|
||||
{
|
||||
yield (vec2(start_x, line.line_top), end_x - start_x);
|
||||
yield (i, start_x, end_x - start_x);
|
||||
return;
|
||||
}
|
||||
yield (vec2(start_x, line.line_top), line.line_w - start_x);
|
||||
yield (i, start_x, line.line_w - start_x);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for line in iter {
|
||||
for (i, line) in iter {
|
||||
if line.line_i > end.line {
|
||||
return;
|
||||
}
|
||||
if line.line_i == end.line
|
||||
&& let Some(end_x) = index_x(&line, end.index)
|
||||
{
|
||||
yield (vec2(0.0, line.line_top), end_x);
|
||||
yield (i, 0.0, end_x);
|
||||
return;
|
||||
}
|
||||
yield (vec2(0.0, line.line_top), line.line_w);
|
||||
yield (i, 0.0, line.line_w);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ impl TextView {
|
||||
}
|
||||
}
|
||||
|
||||
/// region where the text should be draw
|
||||
/// does not include extra height or width from weird unicode
|
||||
pub fn region(&self) -> UiRegion {
|
||||
self.tex()
|
||||
.map(|t| t.size)
|
||||
|
||||
Reference in New Issue
Block a user