Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Make platform input handler private Automatically record the context on non-view input handlers Simplify the async window context update() method
Mikayla33105486aa7c
diff --git a/crates/command_palette/src/command_palette.rs b/crates/command_palette/src/command_palette.rsindex c90e4488656..a1309477937 100644--- a/crates/command_palette/src/command_palette.rs+++ b/crates/command_palette/src/command_palette.rs@@ -311,7 +311,7 @@ impl PickerDelegate for CommandPaletteDelegate {let action = command.action;cx.focus(&self.previous_focus_handle);cx.window_context()- .spawn(move |mut cx| async move { cx.update(|_, cx| cx.dispatch_action(action)) })+ .spawn(move |mut cx| async move { cx.update(|cx| cx.dispatch_action(action)) }).detach_and_log_err(cx);self.dismissed(cx);}diff --git a/crates/copilot_ui/src/copilot_button.rs b/crates/copilot_ui/src/copilot_button.rsindex 9dc4e75cb1c..28b28ffe9af 100644--- a/crates/copilot_ui/src/copilot_button.rs+++ b/crates/copilot_ui/src/copilot_button.rs@@ -355,7 +355,7 @@ fn initiate_sign_in(cx: &mut WindowContext) {cx.spawn(|mut cx| async move {task.await;- if let Some(copilot) = cx.update(|_, cx| Copilot::global(cx)).ok().flatten() {+ if let Some(copilot) = cx.update(|cx| Copilot::global(cx)).ok().flatten() {workspace.update(&mut cx, |workspace, cx| match copilot.read(cx).status() {Status::Authorized => workspace.show_toast(diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 4dc505a8412..409148f59d7 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -57,9 +57,10 @@ use gpui::{div, impl_actions, point, prelude::*, px, relative, rems, size, uniform_list, Action,AnyElement, AppContext, AsyncWindowContext, BackgroundExecutor, Bounds, ClipboardItem, Context,DispatchPhase, ElementId, EventEmitter, FocusHandle, FocusableView, FontStyle, FontWeight,- HighlightStyle, Hsla, InputHandler, InteractiveText, KeyContext, Model, MouseButton,- ParentElement, Pixels, Render, SharedString, Styled, StyledText, Subscription, Task, TextStyle,- UniformListScrollHandle, View, ViewContext, VisualContext, WeakView, WhiteSpace, WindowContext,+ HighlightStyle, Hsla, InteractiveText, KeyContext, Model, MouseButton, ParentElement, Pixels,+ Render, SharedString, Styled, StyledText, Subscription, Task, TextStyle,+ UniformListScrollHandle, View, ViewContext, ViewInputHandler, VisualContext, WeakView,+ WhiteSpace, WindowContext,};use highlight_matching_bracket::refresh_matching_bracket_highlights;use hover_popover::{hide_hover, HoverState};@@ -3378,7 +3379,7 @@ impl Editor {let replica_id = this.update(&mut cx, |this, cx| this.replica_id(cx))?;let mut entries = transaction.0.into_iter().collect::<Vec<_>>();- cx.update(|_, cx| {+ cx.update(|cx| {entries.sort_unstable_by_key(|(buffer, _)| {buffer.read(cx).file().map(|f| f.path().clone())});@@ -9166,7 +9167,7 @@ impl Render for Editor {}}-impl InputHandler for Editor {+impl ViewInputHandler for Editor {fn text_for_range(&mut self,range_utf16: Range<usize>,diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex 4c6efcb02a4..ad166bb42ba 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -2951,9 +2951,10 @@ impl Element for EditorElement {self.register_key_listeners(cx);cx.with_content_mask(Some(ContentMask { bounds }), |cx| {- let input_handler =- ElementInputHandler::new(bounds, self.editor.clone(), cx);- cx.handle_input(&focus_handle, input_handler);+ cx.handle_input(+ &focus_handle,+ ElementInputHandler::new(bounds, self.editor.clone()),+ );self.paint_background(gutter_bounds, text_bounds, &layout, cx);if layout.gutter_size.width > Pixels::ZERO {diff --git a/crates/editor/src/hover_popover.rs b/crates/editor/src/hover_popover.rsindex 609c20ac680..9268c6de4e4 100644--- a/crates/editor/src/hover_popover.rs+++ b/crates/editor/src/hover_popover.rs@@ -247,7 +247,7 @@ fn show_hover(};// query the LSP for hover info- let hover_request = cx.update(|_, cx| {+ let hover_request = cx.update(|cx| {project.update(cx, |project, cx| {project.hover(&buffer, buffer_position, cx)})diff --git a/crates/gpui/src/app/async_context.rs b/crates/gpui/src/app/async_context.rsindex 1ee01d90dfa..7c36aebf57b 100644--- a/crates/gpui/src/app/async_context.rs+++ b/crates/gpui/src/app/async_context.rs@@ -213,7 +213,12 @@ impl AsyncWindowContext {}/// A convenience method for [WindowContext::update()]- pub fn update<R>(+ pub fn update<R>(&mut self, update: impl FnOnce(&mut WindowContext) -> R) -> Result<R> {+ self.app.update_window(self.window, |_, cx| update(cx))+ }++ /// A convenience method for [WindowContext::update()]+ pub fn update_root<R>(&mut self,update: impl FnOnce(AnyView, &mut WindowContext) -> R,) -> Result<R> {diff --git a/crates/gpui/src/elements/div.rs b/crates/gpui/src/elements/div.rsindex aa912eadbe9..fe069a9b6c9 100644--- a/crates/gpui/src/elements/div.rs+++ b/crates/gpui/src/elements/div.rs@@ -1420,7 +1420,7 @@ impl Interactivity {move |mut cx| async move {cx.background_executor().timer(TOOLTIP_DELAY).await;- cx.update(|_, cx| {+ cx.update(|cx| {active_tooltip.borrow_mut().replace(ActiveTooltip {tooltip: Some(AnyTooltip {diff --git a/crates/gpui/src/input.rs b/crates/gpui/src/input.rsindex 7290b48abd7..3440d08ef38 100644--- a/crates/gpui/src/input.rs+++ b/crates/gpui/src/input.rs@@ -1,13 +1,11 @@-use crate::{- AsyncWindowContext, Bounds, Pixels, PlatformInputHandler, View, ViewContext, WindowContext,-};+use crate::{Bounds, InputHandler, Pixels, View, ViewContext, WindowContext};use std::ops::Range;/// Implement this trait to allow views to handle textual input when implementing an editor, field, etc.////// Once your view `V` implements this trait, you can use it to construct an [`ElementInputHandler<V>`]./// This input handler can then be assigned during paint by calling [`WindowContext::handle_input`].-pub trait InputHandler: 'static + Sized {+pub trait ViewInputHandler: 'static + Sized {fn text_for_range(&mut self, range: Range<usize>, cx: &mut ViewContext<Self>)-> Option<String>;fn selected_text_range(&mut self, cx: &mut ViewContext<Self>) -> Option<Range<usize>>;@@ -39,7 +37,6 @@ pub trait InputHandler: 'static + Sized {pub struct ElementInputHandler<V> {view: View<V>,element_bounds: Bounds<Pixels>,- cx: AsyncWindowContext,}impl<V: 'static> ElementInputHandler<V> {@@ -47,45 +44,42 @@ impl<V: 'static> ElementInputHandler<V> {/// containing view.////// [element_paint]: crate::Element::paint- pub fn new(element_bounds: Bounds<Pixels>, view: View<V>, cx: &mut WindowContext) -> Self {+ pub fn new(element_bounds: Bounds<Pixels>, view: View<V>) -> Self {ElementInputHandler {view,element_bounds,- cx: cx.to_async(),}}}-impl<V: InputHandler> PlatformInputHandler for ElementInputHandler<V> {- fn selected_text_range(&mut self) -> Option<Range<usize>> {+impl<V: ViewInputHandler> InputHandler for ElementInputHandler<V> {+ fn selected_text_range(&mut self, cx: &mut WindowContext) -> Option<Range<usize>> {self.view- .update(&mut self.cx, |view, cx| view.selected_text_range(cx))- .ok()- .flatten()+ .update(cx, |view, cx| view.selected_text_range(cx))}- fn marked_text_range(&mut self) -> Option<Range<usize>> {- self.view- .update(&mut self.cx, |view, cx| view.marked_text_range(cx))- .ok()- .flatten()+ fn marked_text_range(&mut self, cx: &mut WindowContext) -> Option<Range<usize>> {+ self.view.update(cx, |view, cx| view.marked_text_range(cx))}- fn text_for_range(&mut self, range_utf16: Range<usize>) -> Option<String> {+ fn text_for_range(+ &mut self,+ range_utf16: Range<usize>,+ cx: &mut WindowContext,+ ) -> Option<String> {self.view- .update(&mut self.cx, |view, cx| {- view.text_for_range(range_utf16, cx)- })- .ok()- .flatten()+ .update(cx, |view, cx| view.text_for_range(range_utf16, cx))}- fn replace_text_in_range(&mut self, replacement_range: Option<Range<usize>>, text: &str) {- self.view- .update(&mut self.cx, |view, cx| {- view.replace_text_in_range(replacement_range, text, cx)- })- .ok();+ fn replace_text_in_range(+ &mut self,+ replacement_range: Option<Range<usize>>,+ text: &str,+ cx: &mut WindowContext,+ ) {+ self.view.update(cx, |view, cx| {+ view.replace_text_in_range(replacement_range, text, cx)+ });}fn replace_and_mark_text_in_range(@@ -93,26 +87,24 @@ impl<V: InputHandler> PlatformInputHandler for ElementInputHandler<V> {range_utf16: Option<Range<usize>>,new_text: &str,new_selected_range: Option<Range<usize>>,+ cx: &mut WindowContext,) {- self.view- .update(&mut self.cx, |view, cx| {- view.replace_and_mark_text_in_range(range_utf16, new_text, new_selected_range, cx)- })- .ok();+ self.view.update(cx, |view, cx| {+ view.replace_and_mark_text_in_range(range_utf16, new_text, new_selected_range, cx)+ });}- fn unmark_text(&mut self) {- self.view- .update(&mut self.cx, |view, cx| view.unmark_text(cx))- .ok();+ fn unmark_text(&mut self, cx: &mut WindowContext) {+ self.view.update(cx, |view, cx| view.unmark_text(cx));}- fn bounds_for_range(&mut self, range_utf16: Range<usize>) -> Option<Bounds<Pixels>> {- self.view- .update(&mut self.cx, |view, cx| {- view.bounds_for_range(range_utf16, self.element_bounds, cx)- })- .ok()- .flatten()+ fn bounds_for_range(+ &mut self,+ range_utf16: Range<usize>,+ cx: &mut WindowContext,+ ) -> Option<Bounds<Pixels>> {+ self.view.update(cx, |view, cx| {+ view.bounds_for_range(range_utf16, self.element_bounds, cx)+ })}}diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rsindex e08d7a85521..cbf5908b067 100644--- a/crates/gpui/src/platform.rs+++ b/crates/gpui/src/platform.rs@@ -6,10 +6,10 @@ mod mac;mod test;use crate::{- Action, AnyWindowHandle, BackgroundExecutor, Bounds, DevicePixels, Font, FontId, FontMetrics,- FontRun, ForegroundExecutor, GlobalPixels, GlyphId, Keymap, LineLayout, Pixels, PlatformInput,- Point, RenderGlyphParams, RenderImageParams, RenderSvgParams, Result, Scene, SharedString,- Size, TaskLabel,+ Action, AnyWindowHandle, AsyncWindowContext, BackgroundExecutor, Bounds, DevicePixels, Font,+ FontId, FontMetrics, FontRun, ForegroundExecutor, GlobalPixels, GlyphId, Keymap, LineLayout,+ Pixels, PlatformInput, Point, RenderGlyphParams, RenderImageParams, RenderSvgParams, Result,+ Scene, SharedString, Size, TaskLabel, WindowContext,};use anyhow::anyhow;use async_task::Runnable;@@ -149,8 +149,8 @@ pub(crate) trait PlatformWindow {fn mouse_position(&self) -> Point<Pixels>;fn modifiers(&self) -> Modifiers;fn as_any_mut(&mut self) -> &mut dyn Any;- fn set_input_handler(&mut self, input_handler: Box<dyn PlatformInputHandler>);- fn take_input_handler(&mut self) -> Option<Box<dyn PlatformInputHandler>>;+ fn set_input_handler(&mut self, input_handler: PlatformInputHandler);+ fn take_input_handler(&mut self) -> Option<PlatformInputHandler>;fn prompt(&self, level: PromptLevel, msg: &str, answers: &[&str]) -> oneshot::Receiver<usize>;fn activate(&self);fn set_title(&mut self, title: &str);@@ -325,19 +325,103 @@ impl From<TileId> for etagere::AllocId {}}-pub trait PlatformInputHandler: 'static {- fn selected_text_range(&mut self) -> Option<Range<usize>>;- fn marked_text_range(&mut self) -> Option<Range<usize>>;- fn text_for_range(&mut self, range_utf16: Range<usize>) -> Option<String>;- fn replace_text_in_range(&mut self, replacement_range: Option<Range<usize>>, text: &str);+pub(crate) struct PlatformInputHandler {+ cx: AsyncWindowContext,+ handler: Box<dyn InputHandler>,+}++impl PlatformInputHandler {+ pub fn new(cx: AsyncWindowContext, handler: Box<dyn InputHandler>) -> Self {+ Self { cx, handler }+ }++ fn selected_text_range(&mut self) -> Option<Range<usize>> {+ self.cx+ .update(|cx| self.handler.selected_text_range(cx))+ .ok()+ .flatten()+ }++ fn marked_text_range(&mut self) -> Option<Range<usize>> {+ self.cx+ .update(|cx| self.handler.marked_text_range(cx))+ .ok()+ .flatten()+ }++ fn text_for_range(&mut self, range_utf16: Range<usize>) -> Option<String> {+ self.cx+ .update(|cx| self.handler.text_for_range(range_utf16, cx))+ .ok()+ .flatten()+ }++ fn replace_text_in_range(&mut self, replacement_range: Option<Range<usize>>, text: &str) {+ self.cx+ .update(|cx| {+ self.handler+ .replace_text_in_range(replacement_range, text, cx)+ })+ .ok();+ }+fn replace_and_mark_text_in_range(&mut self,range_utf16: Option<Range<usize>>,new_text: &str,new_selected_range: Option<Range<usize>>,+ ) {+ self.cx+ .update(|cx| {+ self.handler.replace_and_mark_text_in_range(+ range_utf16,+ new_text,+ new_selected_range,+ cx,+ )+ })+ .ok();+ }++ fn unmark_text(&mut self) {+ self.cx.update(|cx| self.handler.unmark_text(cx)).ok();+ }++ fn bounds_for_range(&mut self, range_utf16: Range<usize>) -> Option<Bounds<Pixels>> {+ self.cx+ .update(|cx| self.handler.bounds_for_range(range_utf16, cx))+ .ok()+ .flatten()+ }+}++pub trait InputHandler: 'static {+ fn selected_text_range(&mut self, cx: &mut WindowContext) -> Option<Range<usize>>;+ fn marked_text_range(&mut self, cx: &mut WindowContext) -> Option<Range<usize>>;+ fn text_for_range(+ &mut self,+ range_utf16: Range<usize>,+ cx: &mut WindowContext,+ ) -> Option<String>;+ fn replace_text_in_range(+ &mut self,+ replacement_range: Option<Range<usize>>,+ text: &str,+ cx: &mut WindowContext,);- fn unmark_text(&mut self);- fn bounds_for_range(&mut self, range_utf16: Range<usize>) -> Option<Bounds<Pixels>>;+ fn replace_and_mark_text_in_range(+ &mut self,+ range_utf16: Option<Range<usize>>,+ new_text: &str,+ new_selected_range: Option<Range<usize>>,+ cx: &mut WindowContext,+ );+ fn unmark_text(&mut self, cx: &mut WindowContext);+ fn bounds_for_range(+ &mut self,+ range_utf16: Range<usize>,+ cx: &mut WindowContext,+ ) -> Option<Bounds<Pixels>>;}#[derive(Debug)]diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rsindex 814b8cc788c..fcfd02aa411 100644--- a/crates/gpui/src/platform/mac/window.rs+++ b/crates/gpui/src/platform/mac/window.rs@@ -1,9 +1,9 @@use super::{global_bounds_from_ns_rect, ns_string, MacDisplay, MetalRenderer, NSRange};use crate::{- global_bounds_to_ns_rect, point, px, size, AnyWindowHandle, Bounds, ExternalPaths,- FileDropEvent, ForegroundExecutor, GlobalPixels, KeyDownEvent, Keystroke, Modifiers,- ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels,- PlatformAtlas, PlatformDisplay, PlatformInput, PlatformInputHandler, PlatformWindow, Point,+ global_bounds_to_ns_rect, platform::PlatformInputHandler, point, px, size, AnyWindowHandle,+ Bounds, ExternalPaths, FileDropEvent, ForegroundExecutor, GlobalPixels, KeyDownEvent,+ Keystroke, Modifiers, ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent,+ MouseUpEvent, Pixels, PlatformAtlas, PlatformDisplay, PlatformInput, PlatformWindow, Point,PromptLevel, Size, Timer, WindowAppearance, WindowBounds, WindowKind, WindowOptions,};use block::ConcreteBlock;@@ -327,7 +327,7 @@ struct MacWindowState {should_close_callback: Option<Box<dyn FnMut() -> bool>>,close_callback: Option<Box<dyn FnOnce()>>,appearance_changed_callback: Option<Box<dyn FnMut()>>,- input_handler: Option<Box<dyn PlatformInputHandler>>,+ input_handler: Option<PlatformInputHandler>,pending_key_down: Option<(KeyDownEvent, Option<InsertText>)>,last_key_equivalent: Option<KeyDownEvent>,synthetic_drag_counter: usize,@@ -764,11 +764,11 @@ impl PlatformWindow for MacWindow {self}- fn set_input_handler(&mut self, input_handler: Box<dyn PlatformInputHandler>) {+ fn set_input_handler(&mut self, input_handler: PlatformInputHandler) {self.0.as_ref().lock().input_handler = Some(input_handler);}- fn take_input_handler(&mut self) -> Option<Box<dyn PlatformInputHandler>> {+ fn take_input_handler(&mut self) -> Option<PlatformInputHandler> {self.0.as_ref().lock().input_handler.take()}@@ -1761,13 +1761,13 @@ fn drag_event_position(window_state: &Mutex<MacWindowState>, dragging_info: id)fn with_input_handler<F, R>(window: &Object, f: F) -> Option<R>where- F: FnOnce(&mut dyn PlatformInputHandler) -> R,+ F: FnOnce(&mut PlatformInputHandler) -> R,{let window_state = unsafe { get_window_state(window) };let mut lock = window_state.as_ref().lock();if let Some(mut input_handler) = lock.input_handler.take() {drop(lock);- let result = f(input_handler.as_mut());+ let result = f(&mut input_handler);window_state.lock().input_handler = Some(input_handler);Some(result)} else {diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rsindex 4e7ba2001a3..81bd8b55b30 100644--- a/crates/gpui/src/window.rs+++ b/crates/gpui/src/window.rs@@ -5,13 +5,13 @@ use crate::{AsyncWindowContext, AvailableSpace, Bounds, BoxShadow, Context, Corners, CursorStyle,DevicePixels, DispatchActionListener, DispatchNodeId, DispatchTree, DisplayId, Edges, Effect,Entity, EntityId, EventEmitter, FileDropEvent, Flatten, FontId, GlobalElementId, GlyphId, Hsla,- ImageData, IsZero, KeyBinding, KeyContext, KeyDownEvent, KeyEvent, KeystrokeEvent, LayoutId,- Model, ModelContext, Modifiers, MonochromeSprite, MouseButton, MouseEvent, MouseMoveEvent,- MouseUpEvent, Path, Pixels, PlatformAtlas, PlatformDisplay, PlatformInput,- PlatformInputHandler, PlatformWindow, Point, PolychromeSprite, PromptLevel, Quad, Render,- RenderGlyphParams, RenderImageParams, RenderSvgParams, ScaledPixels, Scene, Shadow,- SharedString, Size, Style, SubscriberSet, Subscription, Surface, TaffyLayoutEngine, Task,- Underline, UnderlineStyle, View, VisualContext, WeakView, WindowBounds, WindowOptions,+ ImageData, InputHandler, IsZero, KeyBinding, KeyContext, KeyDownEvent, KeyEvent,+ KeystrokeEvent, LayoutId, Model, ModelContext, Modifiers, MonochromeSprite, MouseButton,+ MouseEvent, MouseMoveEvent, MouseUpEvent, Path, Pixels, PlatformAtlas, PlatformDisplay,+ PlatformInput, PlatformInputHandler, PlatformWindow, Point, PolychromeSprite, PromptLevel,+ Quad, Render, RenderGlyphParams, RenderImageParams, RenderSvgParams, ScaledPixels, Scene,+ Shadow, SharedString, Size, Style, SubscriberSet, Subscription, Surface, TaffyLayoutEngine,+ Task, Underline, UnderlineStyle, View, VisualContext, WeakView, WindowBounds, WindowOptions,SUBPIXEL_VARIANTS,};use anyhow::{anyhow, Context as _, Result};@@ -298,7 +298,7 @@ pub(crate) struct ElementStateBox {struct RequestedInputHandler {view_id: EntityId,- handler: Option<Box<dyn PlatformInputHandler>>,+ handler: Option<PlatformInputHandler>,}struct TooltipRequest {@@ -2188,16 +2188,15 @@ impl<'a> WindowContext<'a> {/// rendered.////// [element_input_handler]: crate::ElementInputHandler- pub fn handle_input(- &mut self,- focus_handle: &FocusHandle,- input_handler: impl PlatformInputHandler,- ) {+ pub fn handle_input(&mut self, focus_handle: &FocusHandle, input_handler: impl InputHandler) {if focus_handle.is_focused(self) {let view_id = self.parent_view_id();self.window.next_frame.requested_input_handler = Some(RequestedInputHandler {view_id,- handler: Some(Box::new(input_handler)),+ handler: Some(PlatformInputHandler::new(+ self.to_async(),+ Box::new(input_handler),+ )),})}}@@ -2209,7 +2208,7 @@ impl<'a> WindowContext<'a> {self.window.platform_window.on_should_close(Box::new(move || {- this.update(|_, cx| {+ this.update(|cx| {// Ensure that the window is removed from the app if it's been closed// by always pre-empting the system close event.if f(cx) {diff --git a/crates/journal/src/journal.rs b/crates/journal/src/journal.rsindex b15da05e173..7383a0ee55a 100644--- a/crates/journal/src/journal.rs+++ b/crates/journal/src/journal.rs@@ -102,7 +102,7 @@ pub fn new_journal_entry(app_state: Arc<AppState>, cx: &mut WindowContext) {cx.spawn(|mut cx| async move {let (journal_dir, entry_path) = create_entry.await?;let (workspace, _) = cx- .update(|_, cx| workspace::open_paths(&[journal_dir], &app_state, None, cx))?+ .update(|cx| workspace::open_paths(&[journal_dir], &app_state, None, cx))?.await?;let opened = workspacediff --git a/crates/terminal_view/src/terminal_element.rs b/crates/terminal_view/src/terminal_element.rsindex 29944b54d77..9ab62947fd4 100644--- a/crates/terminal_view/src/terminal_element.rs+++ b/crates/terminal_view/src/terminal_element.rs@@ -1,11 +1,11 @@use editor::{Cursor, HighlightedRange, HighlightedRangeLine};use gpui::{- div, fill, point, px, relative, AnyElement, AsyncWindowContext, AvailableSpace, BorrowWindow,- Bounds, DispatchPhase, Element, ElementId, FocusHandle, Font, FontStyle, FontWeight,- HighlightStyle, Hsla, InteractiveBounds, InteractiveElement, InteractiveElementState,+ div, fill, point, px, relative, AnyElement, AvailableSpace, BorrowWindow, Bounds,+ DispatchPhase, Element, ElementId, FocusHandle, Font, FontStyle, FontWeight, HighlightStyle,+ Hsla, InputHandler, InteractiveBounds, InteractiveElement, InteractiveElementState,Interactivity, IntoElement, LayoutId, Model, ModelContext, ModifiersChangedEvent, MouseButton,- MouseMoveEvent, Pixels, PlatformInputHandler, Point, ShapedLine, StatefulInteractiveElement,- Styled, TextRun, TextStyle, TextSystem, UnderlineStyle, WeakView, WhiteSpace, WindowContext,+ MouseMoveEvent, Pixels, Point, ShapedLine, StatefulInteractiveElement, Styled, TextRun,+ TextStyle, TextSystem, UnderlineStyle, WeakView, WhiteSpace, WindowContext,};use itertools::Itertools;use language::CursorShape;@@ -749,7 +749,6 @@ impl Element for TerminalElement {let origin = bounds.origin + Point::new(layout.gutter, px(0.));let terminal_input_handler = TerminalInputHandler {- cx: cx.to_async(),terminal: self.terminal.clone(),cursor_bounds: layout.cursor@@ -838,37 +837,35 @@ impl IntoElement for TerminalElement {}struct TerminalInputHandler {- cx: AsyncWindowContext,terminal: Model<Terminal>,workspace: WeakView<Workspace>,cursor_bounds: Option<Bounds<Pixels>>,}-impl PlatformInputHandler for TerminalInputHandler {- fn selected_text_range(&mut self) -> Option<std::ops::Range<usize>> {- self.cx- .update(|_, cx| {- if self- .terminal- .read(cx)- .last_content- .mode- .contains(TermMode::ALT_SCREEN)- {- None- } else {- Some(0..0)- }- })- .ok()- .flatten()+impl InputHandler for TerminalInputHandler {+ fn selected_text_range(&mut self, cx: &mut WindowContext) -> Option<std::ops::Range<usize>> {+ if self+ .terminal+ .read(cx)+ .last_content+ .mode+ .contains(TermMode::ALT_SCREEN)+ {+ None+ } else {+ Some(0..0)+ }}- fn marked_text_range(&mut self) -> Option<std::ops::Range<usize>> {+ fn marked_text_range(&mut self, _: &mut WindowContext) -> Option<std::ops::Range<usize>> {None}- fn text_for_range(&mut self, _: std::ops::Range<usize>) -> Option<String> {+ fn text_for_range(+ &mut self,+ _: std::ops::Range<usize>,+ _: &mut WindowContext,+ ) -> Option<String> {None}@@ -876,19 +873,16 @@ impl PlatformInputHandler for TerminalInputHandler {&mut self,_replacement_range: Option<std::ops::Range<usize>>,text: &str,+ cx: &mut WindowContext,) {- self.cx- .update(|_, cx| {- self.terminal.update(cx, |terminal, _| {- terminal.input(text.into());- });+ self.terminal.update(cx, |terminal, _| {+ terminal.input(text.into());+ });- self.workspace- .update(cx, |this, cx| {- let telemetry = this.project().read(cx).client().telemetry().clone();- telemetry.log_edit_event("terminal");- })- .ok();+ self.workspace+ .update(cx, |this, cx| {+ let telemetry = this.project().read(cx).client().telemetry().clone();+ telemetry.log_edit_event("terminal");}).ok();}@@ -898,12 +892,17 @@ impl PlatformInputHandler for TerminalInputHandler {_range_utf16: Option<std::ops::Range<usize>>,_new_text: &str,_new_selected_range: Option<std::ops::Range<usize>>,+ _: &mut WindowContext,) {}- fn unmark_text(&mut self) {}+ fn unmark_text(&mut self, _: &mut WindowContext) {}- fn bounds_for_range(&mut self, _range_utf16: std::ops::Range<usize>) -> Option<Bounds<Pixels>> {+ fn bounds_for_range(+ &mut self,+ _range_utf16: std::ops::Range<usize>,+ _: &mut WindowContext,+ ) -> Option<Bounds<Pixels>> {self.cursor_bounds}}diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rsindex 25e67aa8f47..180667b1138 100644--- a/crates/terminal_view/src/terminal_view.rs+++ b/crates/terminal_view/src/terminal_view.rs@@ -772,7 +772,7 @@ impl Item for TerminalView {.log_err().flatten().or_else(|| {- cx.update(|_, cx| {+ cx.update(|cx| {let strategy = TerminalSettings::get_global(cx).working_directory.clone();workspace.upgrade()diff --git a/crates/workspace/src/notifications.rs b/crates/workspace/src/notifications.rsindex 6e7590c7d38..1b41b7040ce 100644--- a/crates/workspace/src/notifications.rs+++ b/crates/workspace/src/notifications.rs@@ -281,7 +281,7 @@ whereOk(value) => Some(value),Err(err) => {log::error!("TODO {err:?}");- cx.update(|view, cx| {+ cx.update_root(|view, cx| {if let Ok(workspace) = view.downcast::<Workspace>() {workspace.update(cx, |workspace, cx| workspace.show_error(&err, cx))}diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rsindex 17001ed76f0..306ffab90f6 100644--- a/crates/workspace/src/pane.rs+++ b/crates/workspace/src/pane.rs@@ -1092,7 +1092,7 @@ impl Pane {return Ok(true);}- let (mut has_conflict, mut is_dirty, mut can_save, can_save_as) = cx.update(|_, cx| {+ let (mut has_conflict, mut is_dirty, mut can_save, can_save_as) = cx.update(|cx| {(item.has_conflict(cx),item.is_dirty(cx),@@ -1132,7 +1132,7 @@ impl Pane {}} else if is_dirty && (can_save || can_save_as) {if save_intent == SaveIntent::Close {- let will_autosave = cx.update(|_, cx| {+ let will_autosave = cx.update(|cx| {matches!(WorkspaceSettings::get_global(cx).autosave,AutosaveSetting::OnFocusChange | AutosaveSetting::OnWindowChange@@ -1166,7 +1166,7 @@ impl Pane {})?.unwrap_or_else(|| Path::new("").into());- let abs_path = cx.update(|_, cx| cx.prompt_for_new_path(&start_abs_path))?;+ let abs_path = cx.update(|cx| cx.prompt_for_new_path(&start_abs_path))?;if let Some(abs_path) = abs_path.await.ok().flatten() {pane.update(cx, |_, cx| item.save_as(project, abs_path, cx))?.await?;diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rsindex a0f42cec29f..bb7ba143d60 100644--- a/crates/workspace/src/workspace.rs+++ b/crates/workspace/src/workspace.rs@@ -1233,7 +1233,7 @@ impl Workspace {}for (pane, item) in dirty_items {let (singleton, project_entry_ids) =- cx.update(|_, cx| (item.is_singleton(cx), item.project_entry_ids(cx)))?;+ cx.update(|cx| (item.is_singleton(cx), item.project_entry_ids(cx)))?;if singleton || !project_entry_ids.is_empty() {if let Some(ix) =pane.update(&mut cx, |pane, _| pane.index_for_item(item.as_ref()))?@@ -1307,7 +1307,7 @@ impl Workspace {} else {None};- cx.update(|_, cx| open_paths(&paths, &app_state, window_to_replace, cx))?+ cx.update(|cx| open_paths(&paths, &app_state, window_to_replace, cx))?.await?;Ok(())})@@ -1912,7 +1912,7 @@ impl Workspace {let project_item = project.update(cx, |project, cx| project.open_path(path, cx));cx.spawn(|_, mut cx| async move {let (project_entry_id, project_item) = project_item.await?;- let build_item = cx.update(|_, cx| {+ let build_item = cx.update(|cx| {cx.default_global::<ProjectItemBuilders>().get(&project_item.entity_type()).ok_or_else(|| anyhow!("no item builder for project item"))@@ -2709,7 +2709,7 @@ impl Workspace {) -> Result<()> {let this = this.upgrade().context("workspace dropped")?;- let item_builders = cx.update(|_, cx| {+ let item_builders = cx.update(|cx| {cx.default_global::<FollowableItemBuilders>().values().map(|b| b.0)@@ -2728,7 +2728,7 @@ impl Workspace {Err(anyhow!("missing view variant"))?;}for build_item in &item_builders {- let task = cx.update(|_, cx| {+ let task = cx.update(|cx| {build_item(pane.clone(), this.clone(), id, &mut variant, cx)})?;if let Some(task) = task {@@ -3141,7 +3141,7 @@ impl Workspace {center_group = Some((group, active_pane))}- let mut items_by_project_path = cx.update(|_, cx| {+ let mut items_by_project_path = cx.update(|cx| {center_items.unwrap_or_default().into_iter()@@ -3407,7 +3407,7 @@ fn open_items(let restored_project_paths = restored_items.iter().filter_map(|item| {- cx.update(|_, cx| item.as_ref()?.project_path(cx))+ cx.update(|cx| item.as_ref()?.project_path(cx)).ok().flatten()})