mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-09 03:57:39 +00:00
picker: Outline Editor::new
That way crates that use Picker::new do not have to codegen constructor of Editor; tl;dr, 10% of LLVM shaved off of crates like vcs_menu or theme_selector in release mode.
This commit is contained in:
parent
87d3f59515
commit
0755ce6486
1 changed files with 8 additions and 5 deletions
|
@ -58,13 +58,16 @@ impl<D: PickerDelegate> FocusableView for Picker<D> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn create_editor(placeholder: Arc<str>, cx: &mut WindowContext<'_>) -> View<Editor> {
|
||||||
|
cx.new_view(|cx| {
|
||||||
|
let mut editor = Editor::single_line(cx);
|
||||||
|
editor.set_placeholder_text(placeholder, cx);
|
||||||
|
editor
|
||||||
|
})
|
||||||
|
}
|
||||||
impl<D: PickerDelegate> Picker<D> {
|
impl<D: PickerDelegate> Picker<D> {
|
||||||
pub fn new(delegate: D, cx: &mut ViewContext<Self>) -> Self {
|
pub fn new(delegate: D, cx: &mut ViewContext<Self>) -> Self {
|
||||||
let editor = cx.new_view(|cx| {
|
let editor = create_editor(delegate.placeholder_text(), cx);
|
||||||
let mut editor = Editor::single_line(cx);
|
|
||||||
editor.set_placeholder_text(delegate.placeholder_text(), cx);
|
|
||||||
editor
|
|
||||||
});
|
|
||||||
cx.subscribe(&editor, Self::on_input_editor_event).detach();
|
cx.subscribe(&editor, Self::on_input_editor_event).detach();
|
||||||
let mut this = Self {
|
let mut this = Self {
|
||||||
delegate,
|
delegate,
|
||||||
|
|
Loading…
Reference in a new issue