Return an id from Element::element_id instead of calling cx.with_element_id

Co-Authored-By: Julia <julia@zed.dev>
This commit is contained in:
Nathan Sobo 2023-11-14 16:05:28 -07:00
parent 37d0b8424c
commit bef4df5df9
2 changed files with 209 additions and 204 deletions

View file

@ -9409,14 +9409,17 @@ impl Render for Editor {
EditorMode::Full => cx.theme().colors().editor_background,
};
EditorElement::new(EditorStyle {
EditorElement::new(
cx.view(),
EditorStyle {
background,
local_player: cx.theme().players().local(),
text: text_style,
scrollbar_width: px(12.),
syntax: cx.theme().syntax().clone(),
diagnostic_style: cx.theme().diagnostic_style(),
})
},
)
}
}

View file

@ -20,9 +20,9 @@ use collections::{BTreeMap, HashMap};
use gpui::{
point, px, relative, size, transparent_black, Action, AnyElement, AvailableSpace, BorrowWindow,
Bounds, Component, ContentMask, Corners, DispatchPhase, Edges, Element, ElementId,
ElementInputHandler, Entity, Hsla, Line, MouseButton, MouseDownEvent, MouseMoveEvent,
ElementInputHandler, Entity, EntityId, Hsla, Line, MouseButton, MouseDownEvent, MouseMoveEvent,
MouseUpEvent, ParentComponent, Pixels, ScrollWheelEvent, Size, Style, Styled, TextRun,
TextStyle, ViewContext, WindowContext,
TextStyle, View, ViewContext, WindowContext,
};
use itertools::Itertools;
use language::language_settings::ShowWhitespaceSetting;
@ -111,12 +111,16 @@ impl SelectionLayout {
}
pub struct EditorElement {
editor_id: EntityId,
style: EditorStyle,
}
impl EditorElement {
pub fn new(style: EditorStyle) -> Self {
Self { style }
pub fn new(editor: &View<Editor>, style: EditorStyle) -> Self {
Self {
editor_id: editor.entity_id(),
style,
}
}
fn mouse_down(
@ -2404,7 +2408,7 @@ impl Element<Editor> for EditorElement {
type ElementState = ();
fn element_id(&self) -> Option<gpui::ElementId> {
None // todo! can we change the element trait to return an id here from the view context?
Some(self.editor_id.into())
}
fn initialize(
@ -2451,7 +2455,6 @@ impl Element<Editor> for EditorElement {
};
let dispatch_context = editor.dispatch_context(cx);
cx.with_element_id(Some(cx.view().entity_id()), |cx| {
cx.with_key_dispatch(
dispatch_context,
Some(editor.focus_handle.clone()),
@ -2645,7 +2648,6 @@ impl Element<Editor> for EditorElement {
});
},
)
});
}
}