Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Checkpoint
Mikayla3c93b585ab18
diff --git a/crates/gpui2/src/app.rs b/crates/gpui2/src/app.rsindex 9afffeb685a..801047de5fc 100644--- a/crates/gpui2/src/app.rs+++ b/crates/gpui2/src/app.rs@@ -48,15 +48,15 @@ pub struct AppCell {impl AppCell {#[track_caller]pub fn borrow(&self) -> AppRef {- let thread_id = std::thread::current().id();- eprintln!("borrowed {thread_id:?}");+ // let thread_id = std::thread::current().id();+ // eprintln!("borrowed {thread_id:?}");AppRef(self.app.borrow())}#[track_caller]pub fn borrow_mut(&self) -> AppRefMut {- let thread_id = std::thread::current().id();- eprintln!("borrowed {thread_id:?}");+ // let thread_id = std::thread::current().id();+ // eprintln!("borrowed {thread_id:?}");AppRefMut(self.app.borrow_mut())}}diff --git a/crates/gpui2/src/elements/list.rs b/crates/gpui2/src/elements/list.rsindex 01a64f7bd12..7f15af66c42 100644--- a/crates/gpui2/src/elements/list.rs+++ b/crates/gpui2/src/elements/list.rs@@ -1,4 +1,4 @@-use std::ops::Range;+use std::{cmp, ops::Range};use smallvec::SmallVec;@@ -113,14 +113,24 @@ impl<V: 'static> Element<V> for List<V> {if self.item_count > 0 {let item_height = self.measure_item_height(view_state, padded_bounds, cx);- let visible_item_count = (padded_bounds.size.height / item_height) as usize;- let visible_range = 0..visible_item_count;+ let visible_item_count = (padded_bounds.size.height / item_height).ceil() as usize;+ let visible_range = 0..cmp::min(visible_item_count, self.item_count);let mut items = (self.render_items)(view_state, visible_range, cx);+ dbg!(items.len(), self.item_count, visible_item_count);+for (ix, item) in items.iter_mut().enumerate() {item.initialize(view_state, cx);- item.layout(view_state, cx);++ let layout_id = item.layout(view_state, cx);+ cx.compute_layout(+ layout_id,+ Size {+ width: AvailableSpace::Definite(bounds.size.width),+ height: AvailableSpace::Definite(item_height),+ },+ );let offset = padded_bounds.origin + point(px(0.), item_height * ix);cx.with_element_offset(Some(offset), |cx| item.paint(view_state, cx))}diff --git a/crates/gpui2/src/elements/text.rs b/crates/gpui2/src/elements/text.rsindex 4bc37054902..7e771962cd5 100644--- a/crates/gpui2/src/elements/text.rs+++ b/crates/gpui2/src/elements/text.rs@@ -127,6 +127,7 @@ impl<V: 'static> Element<V> for Text<V> {let element_state = element_state.as_ref().expect("measurement has not been performed");+let line_height = element_state.line_height;let mut line_origin = bounds.origin;for line in &element_state.lines {diff --git a/crates/gpui2/src/text_system/line.rs b/crates/gpui2/src/text_system/line.rsindex 63aac96faff..21a7dcea6fc 100644--- a/crates/gpui2/src/text_system/line.rs+++ b/crates/gpui2/src/text_system/line.rs@@ -78,7 +78,6 @@ impl Line {glyph_origin.y += line_height;}prev_glyph_position = glyph.position;- let glyph_origin = glyph_origin + baseline_offset;let mut finished_underline: Option<(Point<Pixels>, UnderlineStyle)> = None;if glyph.index >= run_end {@@ -129,20 +128,22 @@ impl Line {if max_glyph_bounds.intersects(&content_mask.bounds) {if glyph.is_emoji {cx.paint_emoji(- glyph_origin,+ glyph_origin + baseline_offset,run.font_id,glyph.id,self.layout.layout.font_size,)?;} else {cx.paint_glyph(- glyph_origin,+ glyph_origin + baseline_offset,run.font_id,glyph.id,self.layout.layout.font_size,color,)?;}+ } else {+ dbg!(content_mask.bounds, max_glyph_bounds);}}}diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rsindex 880fc6c6cb2..7c05018aa1a 100644--- a/crates/gpui2/src/window.rs+++ b/crates/gpui2/src/window.rs@@ -792,6 +792,7 @@ impl<'a> WindowContext<'a> {}/// Paint a monochrome (non-emoji) glyph into the scene for the current frame at the current z-index.+ /// The y component of the origin is the baseline of the glyph.pub fn paint_glyph(&mut self,origin: Point<Pixels>,@@ -845,6 +846,7 @@ impl<'a> WindowContext<'a> {}/// Paint an emoji glyph into the scene for the current frame at the current z-index.+ /// The y component of the origin is the baseline of the glyph.pub fn paint_emoji(&mut self,origin: Point<Pixels>,diff --git a/crates/picker2/src/picker2.rs b/crates/picker2/src/picker2.rsindex 9b4f8778e2a..3bcf5b92037 100644--- a/crates/picker2/src/picker2.rs+++ b/crates/picker2/src/picker2.rs@@ -21,7 +21,8 @@use std::ops::Range;use gpui::{- div, list, AppContext, Component, Div, Element, ElementId, ParentElement, Render, ViewContext,+ div, list, red, AppContext, Component, Div, Element, ElementId, ParentElement, Render, Styled,+ ViewContext,};// pub struct Picker<D> {@@ -97,15 +98,18 @@ impl<V: PickerDelegate> Picker<V> {impl<V: 'static + PickerDelegate> Picker<V> {pub fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {- div().id(self.id.clone()).child(list(- "candidates",- view.match_count(self.id.clone()),- move |this: &mut V, visible_range, cx| {- visible_range- .map(|ix| this.render_match(ix, false, false, false, self.id.clone(), cx))- .collect()- },- ))+ div().size_full().id(self.id.clone()).child(+ list(+ "candidates",+ view.match_count(self.id.clone()),+ move |this: &mut V, visible_range, cx| {+ visible_range+ .map(|ix| this.render_match(ix, false, false, false, self.id.clone(), cx))+ .collect()+ },+ )+ .size_full(),+ )}}diff --git a/crates/storybook2/src/stories/picker.rs b/crates/storybook2/src/stories/picker.rsindex de983e03268..23d13b83fc8 100644--- a/crates/storybook2/src/stories/picker.rs+++ b/crates/storybook2/src/stories/picker.rs@@ -1,33 +1,64 @@-use gpui::{div, Div, ParentElement, Render, View, VisualContext, WindowContext};+use gpui::{+ black, div, red, Div, Fill, ParentElement, Render, SharedString, Styled, View, VisualContext,+ WindowContext,+};use picker::{Picker, PickerDelegate};pub struct PickerStory {- // picker: View<Picker<PickerStoryDelegate>>,+ candidates: Vec<SharedString>,}impl PickerDelegate for PickerStory {- type ListItem = Div<Self>;+ type ListItem = SharedString;- fn match_count(&self, picker_id: gpui::ElementId) -> usize {- 0+ fn match_count(&self, _picker_id: gpui::ElementId) -> usize {+ self.candidates.len()}fn render_match(&self,ix: usize,- active: bool,- hovered: bool,- selected: bool,- picker_id: gpui::ElementId,+ _active: bool,+ _hovered: bool,+ _selected: bool,+ _picker_id: gpui::ElementId,cx: &mut gpui::ViewContext<Self>,) -> Self::ListItem {- todo!()+ self.candidates[ix].clone()}}impl PickerStory {pub fn new(cx: &mut WindowContext) -> View<Self> {- cx.build_view(|cx| PickerStory {})+ cx.build_view(|cx| PickerStory {+ candidates: vec![+ "Pizza (Italy)".into(),+ "Sushi (Japan)".into(),+ "Paella (Spain)".into(),+ "Tacos (Mexico)".into(),+ "Peking Duck (China)".into(),+ "Fish and Chips (UK)".into(),+ "Croissant (France)".into(),+ "Bratwurst (Germany)".into(),+ "Poutine (Canada)".into(),+ "Chicken Tikka Masala (India)".into(),+ "Feijoada (Brazil)".into(),+ "Kimchi (Korea)".into(),+ "Borscht (Ukraine)".into(),+ "Falafel (Middle East)".into(),+ "Baklava (Turkey)".into(),+ "Shepherd's Pie (Ireland)".into(),+ "Rendang (Indonesia)".into(),+ "Kebab (Middle East)".into(),+ "Ceviche (Peru)".into(),+ "Pierogi (Poland)".into(),+ "Churrasco (Brazil)".into(),+ "Moussaka (Greece)".into(),+ "Lasagna (Italy)".into(),+ "Pad Thai (Thailand)".into(),+ "Pho (Vietnam)".into(),+ ],+ })}}@@ -35,6 +66,9 @@ impl Render for PickerStory {type Element = Div<Self>;fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> Self::Element {- div().child(Picker::new("picker_story"))+ div()+ .text_color(red())+ .size_full()+ .child(Picker::new("picker_story"))}}