Fix window double borrows (#23739)

Fix bugs caused by the window context PR, where the window could be on
the stack and is then requested from the App.
This PR also adds derive macros for `AppContext` and `VisualContext` so
that it's easy to define further contexts in API code, such as
`editor::BlockContext`.

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2025-01-27 13:56:29 -08:00 committed by GitHub
parent 29bfb56739
commit a7c549b85b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 465 additions and 297 deletions

View file

@ -5,8 +5,8 @@ use editor::{
actions::Tab, scroll::Autoscroll, Anchor, Editor, MultiBufferSnapshot, ToOffset, ToPoint,
};
use gpui::{
div, prelude::*, AnyWindowHandle, App, DismissEvent, Entity, EventEmitter, FocusHandle,
Focusable, Render, SharedString, Styled, Subscription,
div, prelude::*, App, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, Render,
SharedString, Styled, Subscription,
};
use language::Buffer;
use settings::Settings;
@ -133,19 +133,15 @@ impl GoToLine {
}
}
fn release(&mut self, window: AnyWindowHandle, cx: &mut App) {
window
.update(cx, |_, window, cx| {
let scroll_position = self.prev_scroll_position.take();
self.active_editor.update(cx, |editor, cx| {
editor.clear_row_highlights::<GoToLineRowHighlights>();
if let Some(scroll_position) = scroll_position {
editor.set_scroll_position(scroll_position, window, cx);
}
cx.notify();
})
})
.ok();
fn release(&mut self, window: &mut Window, cx: &mut App) {
let scroll_position = self.prev_scroll_position.take();
self.active_editor.update(cx, |editor, cx| {
editor.clear_row_highlights::<GoToLineRowHighlights>();
if let Some(scroll_position) = scroll_position {
editor.set_scroll_position(scroll_position, window, cx);
}
cx.notify();
})
}
fn on_line_editor_event(