Merge pull request #576 from zed-industries/cursor-shape

Add support for rendering the cursor as a Block and Underscore

Co-authored-by: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Keith Simmons
2022-03-11 11:51:24 -08:00
committed by GitHub
co-authored by Max Brunsfeld
3 changed files with 114 additions and 13 deletions
+8 -1
View File
@@ -450,6 +450,7 @@ pub struct Editor {
document_highlights_task: Option<Task<()>>,
pending_rename: Option<RenameState>,
searchable: bool,
cursor_shape: CursorShape,
}
pub struct EditorSnapshot {
@@ -930,6 +931,7 @@ impl Editor {
document_highlights_task: Default::default(),
pending_rename: Default::default(),
searchable: true,
cursor_shape: Default::default(),
};
this.end_selection(cx);
this
@@ -1021,6 +1023,11 @@ impl Editor {
cx.notify();
}
pub fn set_cursor_shape(&mut self, cursor_shape: CursorShape, cx: &mut ViewContext<Self>) {
self.cursor_shape = cursor_shape;
cx.notify();
}
pub fn scroll_position(&self, cx: &mut ViewContext<Self>) -> Vector2F {
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
compute_scroll_position(&display_map, self.scroll_position, &self.scroll_top_anchor)
@@ -5584,7 +5591,7 @@ impl View for Editor {
self.display_map.update(cx, |map, cx| {
map.set_font(style.text.font_id, style.text.font_size, cx)
});
EditorElement::new(self.handle.clone(), style.clone()).boxed()
EditorElement::new(self.handle.clone(), style.clone(), self.cursor_shape).boxed()
}
fn ui_name() -> &'static str {