Fixed cursor positioning bugs in multi-byte charcters. Still have at least one though :/

This commit is contained in:
Mikayla Maki
2022-07-01 14:53:19 -07:00
parent 62939322d3
commit 6ac5cc0d2a
3 changed files with 86 additions and 46 deletions
+10 -10
View File
@@ -520,7 +520,7 @@ impl EditorElement {
cursors.push(Cursor {
color: selection_style.cursor,
block_width,
origin: content_origin + vec2f(x, y),
origin: vec2f(x, y),
line_height: layout.line_height,
shape: self.cursor_shape,
block_text,
@@ -546,13 +546,12 @@ impl EditorElement {
cx.scene.push_layer(Some(bounds));
for cursor in cursors {
cursor.paint(cx);
cursor.paint(content_origin, cx);
}
cx.scene.pop_layer();
if let Some((position, context_menu)) = layout.context_menu.as_mut() {
cx.scene.push_stacking_context(None);
let cursor_row_layout = &layout.line_layouts[(position.row() - start_row) as usize];
let x = cursor_row_layout.x_for_index(position.column() as usize) - scroll_left;
let y = (position.row() + 1) as f32 * layout.line_height - scroll_top;
@@ -1658,14 +1657,15 @@ impl Cursor {
}
}
pub fn paint(&self, cx: &mut PaintContext) {
pub fn paint(&self, origin: Vector2F, cx: &mut PaintContext) {
let bounds = match self.shape {
CursorShape::Bar => RectF::new(self.origin, vec2f(2.0, self.line_height)),
CursorShape::Block => {
RectF::new(self.origin, vec2f(self.block_width, self.line_height))
}
CursorShape::Bar => RectF::new(self.origin + origin, vec2f(2.0, self.line_height)),
CursorShape::Block => RectF::new(
self.origin + origin,
vec2f(self.block_width, self.line_height),
),
CursorShape::Underscore => RectF::new(
self.origin + Vector2F::new(0.0, self.line_height - 2.0),
self.origin + origin + Vector2F::new(0.0, self.line_height - 2.0),
vec2f(self.block_width, 2.0),
),
};
@@ -1678,7 +1678,7 @@ impl Cursor {
});
if let Some(block_text) = &self.block_text {
block_text.paint(self.origin, bounds, self.line_height, cx);
block_text.paint(self.origin + origin, bounds, self.line_height, cx);
}
}
}