on master help sign in
Fix bug with auto replacing components in compositor (#1711)
5c810e5Gokul Soumya
helix-term/src/commands.rs+1−1
@@ -2980,7 +2980,7 @@ pub mod cmd {
2980 Box::new(move |editor: &mut Editor, compositor: &mut Compositor| {
2980 Box::new(move |editor: &mut Editor, compositor: &mut Compositor| {
2981 let contents = ui::Markdown::new(contents, editor.syn_loader.clone());
2981 let contents = ui::Markdown::new(contents, editor.syn_loader.clone());
2982 let popup = Popup::new("hover", contents).auto_close(true);
2982 let popup = Popup::new("hover", contents).auto_close(true);
2983− compositor.replace_or_push("hover", Box::new(popup));
2983+ compositor.replace_or_push("hover", popup);
2984 });
2984 });
2985 Ok(call)
2985 Ok(call)
2986 };
2986 };
helix-term/src/commands/lsp.rs+2−2
@@ -254,7 +254,7 @@ pub fn code_action(cx: &mut Context) {
254 vertical: 1,
254 vertical: 1,
255 horizontal: 1,
255 horizontal: 1,
256 });
256 });
257− compositor.replace_or_push("code-action", Box::new(popup));
257+ compositor.replace_or_push("code-action", popup);
258 },
258 },
259 )
259 )
260}
260}
@@ -637,7 +637,7 @@ pub fn hover(cx: &mut Context) {
637
637
638 let contents = ui::Markdown::new(contents, editor.syn_loader.clone());
638 let contents = ui::Markdown::new(contents, editor.syn_loader.clone());
639 let popup = Popup::new("hover", contents).auto_close(true);
639 let popup = Popup::new("hover", contents).auto_close(true);
640− compositor.replace_or_push("hover", Box::new(popup));
640+ compositor.replace_or_push("hover", popup);
641 }
641 }
642 },
642 },
643 );
643 );
helix-term/src/compositor.rs+3−4
@@ -128,11 +128,11 @@ impl Compositor {
128
128
129 /// Replace a component that has the given `id` with the new layer and if
129 /// Replace a component that has the given `id` with the new layer and if
130 /// no component is found, push the layer normally.
130 /// no component is found, push the layer normally.
131− pub fn replace_or_push(&mut self, id: &'static str, layer: Box<dyn Component>) {
131+ pub fn replace_or_push<T: Component>(&mut self, id: &'static str, layer: T) {
132 if let Some(component) = self.find_id(id) {
132 if let Some(component) = self.find_id(id) {
133 *component = layer;
133 *component = layer;
134 } else {
134 } else {
135− self.push(layer)
135+ self.push(Box::new(layer))
136 }
136 }
137 }
137 }
138
138
@@ -221,10 +221,9 @@ impl Compositor {
221 }
221 }
222
222
223 pub fn find_id<T: 'static>(&mut self, id: &'static str) -> Option<&mut T> {
223 pub fn find_id<T: 'static>(&mut self, id: &'static str) -> Option<&mut T> {
224− let type_name = std::any::type_name::<T>();
225 self.layers
224 self.layers
226 .iter_mut()
225 .iter_mut()
227− .find(|component| component.type_name() == type_name && component.id() == Some(id))
226+ .find(|component| component.id() == Some(id))
228 .and_then(|component| component.as_any_mut().downcast_mut())
227 .and_then(|component| component.as_any_mut().downcast_mut())
229 }
228 }
230}
229}