Eliminate GPUI View, ViewContext, and WindowContext types (#22632)
There's still a bit more work to do on this, but this PR is compiling (with warnings) after eliminating the key types. When the tasks below are complete, this will be the new narrative for GPUI: - `Entity<T>` - This replaces `View<T>`/`Model<T>`. It represents a unit of state, and if `T` implements `Render`, then `Entity<T>` implements `Element`. - `&mut App` This replaces `AppContext` and represents the app. - `&mut Context<T>` This replaces `ModelContext` and derefs to `App`. It is provided by the framework when updating an entity. - `&mut Window` Broken out of `&mut WindowContext` which no longer exists. Every method that once took `&mut WindowContext` now takes `&mut Window, &mut App` and every method that took `&mut ViewContext<T>` now takes `&mut Window, &mut Context<T>` Not pictured here are the two other failed attempts. It's been quite a month! Tasks: - [x] Remove `View`, `ViewContext`, `WindowContext` and thread through `Window` - [x] [@cole-miller @mikayla-maki] Redraw window when entities change - [x] [@cole-miller @mikayla-maki] Get examples and Zed running - [x] [@cole-miller @mikayla-maki] Fix Zed rendering - [x] [@mikayla-maki] Fix todo! macros and comments - [x] Fix a bug where the editor would not be redrawn because of view caching - [x] remove publicness window.notify() and replace with `AppContext::notify` - [x] remove `observe_new_window_models`, replace with `observe_new_models` with an optional window - [x] Fix a bug where the project panel would not be redrawn because of the wrong refresh() call being used - [x] Fix the tests - [x] Fix warnings by eliminating `Window` params or using `_` - [x] Fix conflicts - [x] Simplify generic code where possible - [x] Rename types - [ ] Update docs ### issues post merge - [x] Issues switching between normal and insert mode - [x] Assistant re-rendering failure - [x] Vim test failures - [x] Mac build issue Release Notes: - N/A --------- Co-authored-by: Antonio Scandurra <me@as-cii.com> Co-authored-by: Cole Miller <cole@zed.dev> Co-authored-by: Mikayla <mikayla@zed.dev> Co-authored-by: Joseph <joseph@zed.dev> Co-authored-by: max <max@zed.dev> Co-authored-by: Michael Sloan <michael@zed.dev> Co-authored-by: Mikayla Maki <mikaylamaki@Mikaylas-MacBook-Pro.local> Co-authored-by: Mikayla <mikayla.c.maki@gmail.com> Co-authored-by: joão <joao@zed.dev>
This commit is contained in:
parent
21b4a0d50e
commit
6fca1d2b0b
648 changed files with 36248 additions and 28208 deletions
|
@ -6,7 +6,7 @@ use crate::{
|
|||
SelectMode, ToDisplayPoint, ToggleCodeActions,
|
||||
};
|
||||
use gpui::prelude::FluentBuilder;
|
||||
use gpui::{DismissEvent, Pixels, Point, Subscription, View, ViewContext};
|
||||
use gpui::{Context, DismissEvent, Entity, Focusable as _, Pixels, Point, Subscription, Window};
|
||||
use std::ops::Range;
|
||||
use text::PointUtf16;
|
||||
use workspace::OpenInTerminal;
|
||||
|
@ -26,7 +26,7 @@ pub enum MenuPosition {
|
|||
|
||||
pub struct MouseContextMenu {
|
||||
pub(crate) position: MenuPosition,
|
||||
pub(crate) context_menu: View<ui::ContextMenu>,
|
||||
pub(crate) context_menu: Entity<ui::ContextMenu>,
|
||||
_subscription: Subscription,
|
||||
}
|
||||
|
||||
|
@ -44,37 +44,45 @@ impl MouseContextMenu {
|
|||
editor: &mut Editor,
|
||||
source: multi_buffer::Anchor,
|
||||
position: Point<Pixels>,
|
||||
context_menu: View<ui::ContextMenu>,
|
||||
cx: &mut ViewContext<Editor>,
|
||||
context_menu: Entity<ui::ContextMenu>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Editor>,
|
||||
) -> Option<Self> {
|
||||
let editor_snapshot = editor.snapshot(cx);
|
||||
let editor_snapshot = editor.snapshot(window, cx);
|
||||
let content_origin = editor.last_bounds?.origin
|
||||
+ Point {
|
||||
x: editor.gutter_dimensions.width,
|
||||
y: Pixels(0.0),
|
||||
};
|
||||
let source_position = editor.to_pixel_point(source, &editor_snapshot, cx)?;
|
||||
let source_position = editor.to_pixel_point(source, &editor_snapshot, window)?;
|
||||
let menu_position = MenuPosition::PinnedToEditor {
|
||||
source,
|
||||
offset: position - (source_position + content_origin),
|
||||
};
|
||||
return Some(MouseContextMenu::new(menu_position, context_menu, cx));
|
||||
return Some(MouseContextMenu::new(
|
||||
menu_position,
|
||||
context_menu,
|
||||
window,
|
||||
cx,
|
||||
));
|
||||
}
|
||||
|
||||
pub(crate) fn new(
|
||||
position: MenuPosition,
|
||||
context_menu: View<ui::ContextMenu>,
|
||||
cx: &mut ViewContext<Editor>,
|
||||
context_menu: Entity<ui::ContextMenu>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Editor>,
|
||||
) -> Self {
|
||||
let context_menu_focus = context_menu.focus_handle(cx);
|
||||
cx.focus(&context_menu_focus);
|
||||
window.focus(&context_menu_focus);
|
||||
|
||||
let _subscription = cx.subscribe(
|
||||
let _subscription = cx.subscribe_in(
|
||||
&context_menu,
|
||||
move |editor, _, _event: &DismissEvent, cx| {
|
||||
window,
|
||||
move |editor, _, _event: &DismissEvent, window, cx| {
|
||||
editor.mouse_context_menu.take();
|
||||
if context_menu_focus.contains_focused(cx) {
|
||||
editor.focus(cx);
|
||||
if context_menu_focus.contains_focused(window, cx) {
|
||||
window.focus(&editor.focus_handle(cx));
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -106,10 +114,11 @@ pub fn deploy_context_menu(
|
|||
editor: &mut Editor,
|
||||
position: Option<Point<Pixels>>,
|
||||
point: DisplayPoint,
|
||||
cx: &mut ViewContext<Editor>,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Editor>,
|
||||
) {
|
||||
if !editor.is_focused(cx) {
|
||||
editor.focus(cx);
|
||||
if !editor.is_focused(window) {
|
||||
window.focus(&editor.focus_handle(cx));
|
||||
}
|
||||
|
||||
// Don't show context menu for inline editors
|
||||
|
@ -120,7 +129,7 @@ pub fn deploy_context_menu(
|
|||
let display_map = editor.selections.display_map(cx);
|
||||
let source_anchor = display_map.display_point_to_anchor(point, text::Bias::Right);
|
||||
let context_menu = if let Some(custom) = editor.custom_context_menu.take() {
|
||||
let menu = custom(editor, point, cx);
|
||||
let menu = custom(editor, point, window, cx);
|
||||
editor.custom_context_menu = Some(custom);
|
||||
let Some(menu) = menu else {
|
||||
return;
|
||||
|
@ -133,17 +142,17 @@ pub fn deploy_context_menu(
|
|||
}
|
||||
|
||||
let display_map = editor.selections.display_map(cx);
|
||||
let buffer = &editor.snapshot(cx).buffer_snapshot;
|
||||
let buffer = &editor.snapshot(window, cx).buffer_snapshot;
|
||||
let anchor = buffer.anchor_before(point.to_point(&display_map));
|
||||
if !display_ranges(&display_map, &editor.selections).any(|r| r.contains(&point)) {
|
||||
// Move the cursor to the clicked location so that dispatched actions make sense
|
||||
editor.change_selections(None, cx, |s| {
|
||||
editor.change_selections(None, window, cx, |s| {
|
||||
s.clear_disjoint();
|
||||
s.set_pending_anchor_range(anchor..anchor, SelectMode::Character);
|
||||
});
|
||||
}
|
||||
|
||||
let focus = cx.focused();
|
||||
let focus = window.focused(cx);
|
||||
let has_reveal_target = editor.target_file(cx).is_some();
|
||||
let reveal_in_finder_label = if cfg!(target_os = "macos") {
|
||||
"Reveal in Finder"
|
||||
|
@ -161,7 +170,7 @@ pub fn deploy_context_menu(
|
|||
})
|
||||
});
|
||||
|
||||
ui::ContextMenu::build(cx, |menu, _cx| {
|
||||
ui::ContextMenu::build(window, cx, |menu, _window, _cx| {
|
||||
let builder = menu
|
||||
.on_blur_subscription(Subscription::new(|| {}))
|
||||
.action("Go to Definition", Box::new(GoToDefinition))
|
||||
|
@ -211,15 +220,25 @@ pub fn deploy_context_menu(
|
|||
};
|
||||
|
||||
editor.mouse_context_menu = match position {
|
||||
Some(position) => {
|
||||
MouseContextMenu::pinned_to_editor(editor, source_anchor, position, context_menu, cx)
|
||||
}
|
||||
Some(position) => MouseContextMenu::pinned_to_editor(
|
||||
editor,
|
||||
source_anchor,
|
||||
position,
|
||||
context_menu,
|
||||
window,
|
||||
cx,
|
||||
),
|
||||
None => {
|
||||
let menu_position = MenuPosition::PinnedToEditor {
|
||||
source: source_anchor,
|
||||
offset: editor.character_size(cx),
|
||||
offset: editor.character_size(window),
|
||||
};
|
||||
Some(MouseContextMenu::new(menu_position, context_menu, cx))
|
||||
Some(MouseContextMenu::new(
|
||||
menu_position,
|
||||
context_menu,
|
||||
window,
|
||||
cx,
|
||||
))
|
||||
}
|
||||
};
|
||||
cx.notify();
|
||||
|
@ -254,9 +273,9 @@ mod tests {
|
|||
do_wˇork();
|
||||
}
|
||||
"});
|
||||
cx.editor(|editor, _app| assert!(editor.mouse_context_menu.is_none()));
|
||||
cx.update_editor(|editor, cx| {
|
||||
deploy_context_menu(editor, Some(Default::default()), point, cx)
|
||||
cx.editor(|editor, _window, _app| assert!(editor.mouse_context_menu.is_none()));
|
||||
cx.update_editor(|editor, window, cx| {
|
||||
deploy_context_menu(editor, Some(Default::default()), point, window, cx)
|
||||
});
|
||||
|
||||
cx.assert_editor_state(indoc! {"
|
||||
|
@ -264,6 +283,6 @@ mod tests {
|
|||
do_wˇork();
|
||||
}
|
||||
"});
|
||||
cx.editor(|editor, _app| assert!(editor.mouse_context_menu.is_some()));
|
||||
cx.editor(|editor, _window, _app| assert!(editor.mouse_context_menu.is_some()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue