diff --git a/crates/command_palette/src/command_palette.rs b/crates/command_palette/src/command_palette.rs index c90e448865..a130947793 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.rs index 9dc4e75cb1..28b28ffe9a 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.rs index 4dc505a841..409148f59d 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::>(); - 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, diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 4c6efcb02a..ad166bb42b 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.rs index 609c20ac68..9268c6de4e 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.rs index 1ee01d90df..7c36aebf57 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( + pub fn update(&mut self, update: impl FnOnce(&mut WindowContext) -> R) -> Result { + self.app.update_window(self.window, |_, cx| update(cx)) + } + + /// A convenience method for [WindowContext::update()] + pub fn update_root( &mut self, update: impl FnOnce(AnyView, &mut WindowContext) -> R, ) -> Result { diff --git a/crates/gpui/src/elements/div.rs b/crates/gpui/src/elements/div.rs index aa912eadbe..fe069a9b6c 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.rs index 7290b48abd..3440d08ef3 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`]. /// 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, cx: &mut ViewContext) -> Option; fn selected_text_range(&mut self, cx: &mut ViewContext) -> Option>; @@ -39,7 +37,6 @@ pub trait InputHandler: 'static + Sized { pub struct ElementInputHandler { view: View, element_bounds: Bounds, - cx: AsyncWindowContext, } impl ElementInputHandler { @@ -47,45 +44,42 @@ impl ElementInputHandler { /// containing view. /// /// [element_paint]: crate::Element::paint - pub fn new(element_bounds: Bounds, view: View, cx: &mut WindowContext) -> Self { + pub fn new(element_bounds: Bounds, view: View) -> Self { ElementInputHandler { view, element_bounds, - cx: cx.to_async(), } } } -impl PlatformInputHandler for ElementInputHandler { - fn selected_text_range(&mut self) -> Option> { +impl InputHandler for ElementInputHandler { + fn selected_text_range(&mut self, cx: &mut WindowContext) -> Option> { 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> { - 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> { + self.view.update(cx, |view, cx| view.marked_text_range(cx)) } - fn text_for_range(&mut self, range_utf16: Range) -> Option { + fn text_for_range( + &mut self, + range_utf16: Range, + cx: &mut WindowContext, + ) -> Option { 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>, 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>, + 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 PlatformInputHandler for ElementInputHandler { range_utf16: Option>, new_text: &str, new_selected_range: Option>, + 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) -> Option> { - 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, + cx: &mut WindowContext, + ) -> Option> { + 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.rs index e08d7a8552..cbf5908b06 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; fn modifiers(&self) -> Modifiers; fn as_any_mut(&mut self) -> &mut dyn Any; - fn set_input_handler(&mut self, input_handler: Box); - fn take_input_handler(&mut self) -> Option>; + fn set_input_handler(&mut self, input_handler: PlatformInputHandler); + fn take_input_handler(&mut self) -> Option; fn prompt(&self, level: PromptLevel, msg: &str, answers: &[&str]) -> oneshot::Receiver; fn activate(&self); fn set_title(&mut self, title: &str); @@ -325,19 +325,103 @@ impl From for etagere::AllocId { } } -pub trait PlatformInputHandler: 'static { - fn selected_text_range(&mut self) -> Option>; - fn marked_text_range(&mut self) -> Option>; - fn text_for_range(&mut self, range_utf16: Range) -> Option; - fn replace_text_in_range(&mut self, replacement_range: Option>, text: &str); +pub(crate) struct PlatformInputHandler { + cx: AsyncWindowContext, + handler: Box, +} + +impl PlatformInputHandler { + pub fn new(cx: AsyncWindowContext, handler: Box) -> Self { + Self { cx, handler } + } + + fn selected_text_range(&mut self) -> Option> { + self.cx + .update(|cx| self.handler.selected_text_range(cx)) + .ok() + .flatten() + } + + fn marked_text_range(&mut self) -> Option> { + self.cx + .update(|cx| self.handler.marked_text_range(cx)) + .ok() + .flatten() + } + + fn text_for_range(&mut self, range_utf16: Range) -> Option { + self.cx + .update(|cx| self.handler.text_for_range(range_utf16, cx)) + .ok() + .flatten() + } + + fn replace_text_in_range(&mut self, replacement_range: Option>, 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>, new_text: &str, new_selected_range: Option>, + ) { + 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) -> Option> { + 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>; + fn marked_text_range(&mut self, cx: &mut WindowContext) -> Option>; + fn text_for_range( + &mut self, + range_utf16: Range, + cx: &mut WindowContext, + ) -> Option; + fn replace_text_in_range( + &mut self, + replacement_range: Option>, + text: &str, + cx: &mut WindowContext, ); - fn unmark_text(&mut self); - fn bounds_for_range(&mut self, range_utf16: Range) -> Option>; + fn replace_and_mark_text_in_range( + &mut self, + range_utf16: Option>, + new_text: &str, + new_selected_range: Option>, + cx: &mut WindowContext, + ); + fn unmark_text(&mut self, cx: &mut WindowContext); + fn bounds_for_range( + &mut self, + range_utf16: Range, + cx: &mut WindowContext, + ) -> Option>; } #[derive(Debug)] diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index 814b8cc788..fcfd02aa41 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 bool>>, close_callback: Option>, appearance_changed_callback: Option>, - input_handler: Option>, + input_handler: Option, pending_key_down: Option<(KeyDownEvent, Option)>, last_key_equivalent: Option, synthetic_drag_counter: usize, @@ -764,11 +764,11 @@ impl PlatformWindow for MacWindow { self } - fn set_input_handler(&mut self, input_handler: Box) { + 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> { + fn take_input_handler(&mut self) -> Option { self.0.as_ref().lock().input_handler.take() } @@ -1761,13 +1761,13 @@ fn drag_event_position(window_state: &Mutex, dragging_info: id) fn with_input_handler(window: &Object, f: F) -> Option 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.rs index 4e7ba2001a..81bd8b55b3 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>, + handler: Option, } 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.rs index b15da05e17..7383a0ee55 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, 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 = workspace diff --git a/crates/terminal_view/src/terminal_element.rs b/crates/terminal_view/src/terminal_element.rs index 29944b54d7..9ab62947fd 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, workspace: WeakView, cursor_bounds: Option>, } -impl PlatformInputHandler for TerminalInputHandler { - fn selected_text_range(&mut self) -> Option> { - 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> { + if self + .terminal + .read(cx) + .last_content + .mode + .contains(TermMode::ALT_SCREEN) + { + None + } else { + Some(0..0) + } } - fn marked_text_range(&mut self) -> Option> { + fn marked_text_range(&mut self, _: &mut WindowContext) -> Option> { None } - fn text_for_range(&mut self, _: std::ops::Range) -> Option { + fn text_for_range( + &mut self, + _: std::ops::Range, + _: &mut WindowContext, + ) -> Option { None } @@ -876,19 +873,16 @@ impl PlatformInputHandler for TerminalInputHandler { &mut self, _replacement_range: Option>, 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>, _new_text: &str, _new_selected_range: Option>, + _: &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) -> Option> { + fn bounds_for_range( + &mut self, + _range_utf16: std::ops::Range, + _: &mut WindowContext, + ) -> Option> { self.cursor_bounds } } diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index 25e67aa8f4..180667b113 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.rs index 6e7590c7d3..1b41b7040c 100644 --- a/crates/workspace/src/notifications.rs +++ b/crates/workspace/src/notifications.rs @@ -281,7 +281,7 @@ where Ok(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.update(cx, |workspace, cx| workspace.show_error(&err, cx)) } diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 17001ed76f..306ffab90f 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.rs index a0f42cec29..bb7ba143d6 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::() .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::() .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() })