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