Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Merge branch 'main' into focus-handlers-on-draw
Julia4be84f3db0d8
diff --cc crates/gpui2/src/elements/div.rsindex 3ec0a46fcbf,0a8717ca2fd..1f56f449004--- a/crates/gpui2/src/elements/div.rs+++ b/crates/gpui2/src/elements/div.rs@@@ -1,10 -1,12 +1,11 @@@use crate::{point, px, Action, AnyDrag, AnyElement, AnyTooltip, AnyView, AppContext, BorrowAppContext,- BorrowWindow, Bounds, ClickEvent, DispatchPhase, Element, ElementId, FocusEvent, FocusHandle,- IntoElement, KeyContext, KeyDownEvent, KeyUpEvent, LayoutId, MouseButton, MouseDownEvent,- MouseMoveEvent, MouseUpEvent, ParentElement, Pixels, Point, Render, ScrollWheelEvent,- SharedString, Size, StackingOrder, Style, StyleRefinement, Styled, Task, View, Visibility,- WindowContext,+ BorrowWindow, Bounds, ClickEvent, DispatchPhase, Element, ElementId, FocusHandle, IntoElement,+ KeyContext, KeyDownEvent, KeyUpEvent, LayoutId, MouseButton, MouseDownEvent, MouseMoveEvent,+ MouseUpEvent, ParentElement, Pixels, Point, Render, ScrollWheelEvent, SharedString, Size,+ StackingOrder, Style, StyleRefinement, Styled, Task, View, Visibility, WindowContext,};+use collections::HashMap;use refineable::Refineable;use smallvec::SmallVec;diff --cc crates/gpui2/src/window.rsindex 557b2155f86,daa43804b00..e2f53f73472--- a/crates/gpui2/src/window.rs+++ b/crates/gpui2/src/window.rs@@@ -1,18 -1,18 +1,18 @@@use crate::{- key_dispatch::DispatchActionListener, px, size, Action, AnyDrag, AnyView, AppContext,- AsyncWindowContext, AvailableSpace, Bounds, BoxShadow, Context, Corners, CursorStyle,- DevicePixels, DispatchNodeId, DispatchTree, DisplayId, Edges, Effect, Entity, EntityId,- EventEmitter, FileDropEvent, Flatten, FontId, GlobalElementId, GlyphId, Hsla, ImageData,- InputEvent, IsZero, KeyBinding, KeyContext, KeyDownEvent, KeystrokeEvent, LayoutId, Model,- ModelContext, Modifiers, MonochromeSprite, MouseButton, MouseMoveEvent, MouseUpEvent, Path,- Pixels, PlatformAtlas, PlatformDisplay, PlatformInputHandler, PlatformWindow, Point,+ key_dispatch::DispatchActionListener, px, size, transparent_black, Action, AnyDrag, AnyView,+ AppContext, AsyncWindowContext, AvailableSpace, Bounds, BoxShadow, Context, Corners,+ CursorStyle, DevicePixels, DispatchNodeId, DispatchTree, DisplayId, Edges, Effect, Entity,- EntityId, EventEmitter, FileDropEvent, Flatten, FocusEvent, FontId, GlobalElementId, GlyphId,- Hsla, ImageData, InputEvent, IsZero, KeyBinding, KeyContext, KeyDownEvent, KeystrokeEvent,- LayoutId, Model, ModelContext, Modifiers, MonochromeSprite, MouseButton, MouseMoveEvent,- MouseUpEvent, Path, Pixels, PlatformAtlas, PlatformDisplay, PlatformInputHandler,- PlatformWindow, Point, PolychromeSprite, PromptLevel, Quad, Render, RenderGlyphParams,- RenderImageParams, RenderSvgParams, ScaledPixels, Scene, SceneBuilder, Shadow, SharedString,- Size, Style, SubscriberSet, Subscription, Surface, TaffyLayoutEngine, Task, Underline,- UnderlineStyle, View, VisualContext, WeakView, WindowBounds, WindowOptions, SUBPIXEL_VARIANTS,++ EntityId, EventEmitter, FileDropEvent, Flatten, FontId, GlobalElementId, GlyphId, Hsla,++ ImageData, InputEvent, IsZero, KeyBinding, KeyContext, KeyDownEvent, KeystrokeEvent, LayoutId,++ Model, ModelContext, Modifiers, MonochromeSprite, MouseButton, MouseMoveEvent, MouseUpEvent,++ Path, Pixels, PlatformAtlas, PlatformDisplay, PlatformInputHandler, PlatformWindow, Point,+ PolychromeSprite, PromptLevel, Quad, Render, RenderGlyphParams, RenderImageParams,+ RenderSvgParams, ScaledPixels, Scene, SceneBuilder, Shadow, SharedString, Size, Style,+ SubscriberSet, Subscription, Surface, TaffyLayoutEngine, Task, Underline, UnderlineStyle, View,+ VisualContext, WeakView, WindowBounds, WindowOptions, SUBPIXEL_VARIANTS,};use anyhow::{anyhow, Context as _, Result};- use collections::HashMap;+ use collections::FxHashMap;use derive_more::{Deref, DerefMut};use futures::{channel::{mpsc, oneshot},@@@ -231,21 -239,21 +243,23 @@@ pub struct Windowpub(crate) rendered_frame: Frame,pub(crate) next_frame: Frame,pub(crate) focus_handles: Arc<RwLock<SlotMap<FocusId, AtomicUsize>>>,- pub(crate) focus_listeners: SubscriberSet<(), AnyWindowFocusListener>,- pub(crate) blur_listeners: SubscriberSet<(), AnyObserver>,+ focus_listeners: SubscriberSet<(), AnyWindowFocusListener>,+ blur_listeners: SubscriberSet<(), AnyObserver>,default_prevented: bool,mouse_position: Point<Pixels>,+ modifiers: Modifiers,requested_cursor_style: Option<CursorStyle>,scale_factor: f32,bounds: WindowBounds,bounds_observers: SubscriberSet<(), AnyObserver>,active: bool,pub(crate) dirty: bool,+ pub(crate) drawing: bool,activation_observers: SubscriberSet<(), AnyObserver>,- pub(crate) last_blur: Option<Option<FocusId>>,pub(crate) focus: Option<FocusId>,++ #[cfg(any(test, feature = "test-support"))]+ pub(crate) focus_invalidated: bool,}pub(crate) struct ElementStateBox {@@@ -256,10 -264,10 +270,10 @@@// #[derive(Default)]pub(crate) struct Frame {+ focus: Option<FocusId>,- pub(crate) element_states: HashMap<GlobalElementId, ElementStateBox>,- mouse_listeners: HashMap<TypeId, Vec<(StackingOrder, AnyMouseListener)>>,+ pub(crate) element_states: FxHashMap<GlobalElementId, ElementStateBox>,+ mouse_listeners: FxHashMap<TypeId, Vec<(StackingOrder, AnyMouseListener)>>,pub(crate) dispatch_tree: DispatchTree,- pub(crate) focus_listeners: Vec<AnyFocusListener>,pub(crate) scene_builder: SceneBuilder,pub(crate) depth_map: Vec<(StackingOrder, Bounds<Pixels>)>,pub(crate) z_index_stack: StackingOrder,@@@ -270,10 -278,10 +284,10 @@@impl Frame {fn new(dispatch_tree: DispatchTree) -> Self {Frame {+ focus: None,- element_states: HashMap::default(),- mouse_listeners: HashMap::default(),+ element_states: FxHashMap::default(),+ mouse_listeners: FxHashMap::default(),dispatch_tree,- focus_listeners: Vec::new(),scene_builder: SceneBuilder::default(),z_index_stack: StackingOrder::default(),depth_map: Default::default(),@@@ -382,11 -387,10 +398,12 @@@ impl Windowbounds_observers: SubscriberSet::new(),active: false,dirty: false,+ drawing: false,activation_observers: SubscriberSet::new(),- last_blur: None,focus: None,++ #[cfg(any(test, feature = "test-support"))]+ focus_invalidated: false,}}}@@@ -1238,11 -1254,20 +1256,15 @@@ impl<'a> WindowContext<'a>/// Draw pixels to the display for this window based on the contents of its scene.pub(crate) fn draw(&mut self) -> Scene {+ let t0 = std::time::Instant::now();+ self.window.dirty = false;+ self.window.drawing = true;+- let window_was_focused = self- .window- .focus- .and_then(|focus_id| {- self.window- .rendered_frame- .dispatch_tree- .focusable_node_id(focus_id)- })- .is_some();+ #[cfg(any(test, feature = "test-support"))]+ {+ self.window.focus_invalidated = false;+ }+self.text_system().start_frame();self.window.platform_window.clear_input_handler();self.window.layout_engine.as_mut().unwrap().clear();