Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with auto replacing components in compositor #1711

Merged
merged 2 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2922,7 +2922,7 @@ pub mod cmd {
Box::new(move |editor: &mut Editor, compositor: &mut Compositor| {
let contents = ui::Markdown::new(contents, editor.syn_loader.clone());
let popup = Popup::new("hover", contents).auto_close(true);
compositor.replace_or_push("hover", Box::new(popup));
compositor.replace_or_push("hover", popup);
});
Ok(call)
};
Expand Down
4 changes: 2 additions & 2 deletions helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ pub fn code_action(cx: &mut Context) {
vertical: 1,
horizontal: 1,
});
compositor.replace_or_push("code-action", Box::new(popup));
compositor.replace_or_push("code-action", popup);
},
)
}
Expand Down Expand Up @@ -637,7 +637,7 @@ pub fn hover(cx: &mut Context) {

let contents = ui::Markdown::new(contents, editor.syn_loader.clone());
let popup = Popup::new("hover", contents).auto_close(true);
compositor.replace_or_push("hover", Box::new(popup));
compositor.replace_or_push("hover", popup);
}
},
);
Expand Down
7 changes: 3 additions & 4 deletions helix-term/src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ impl Compositor {

/// Replace a component that has the given `id` with the new layer and if
/// no component is found, push the layer normally.
pub fn replace_or_push(&mut self, id: &'static str, layer: Box<dyn Component>) {
pub fn replace_or_push<T: Component>(&mut self, id: &'static str, layer: T) {
if let Some(component) = self.find_id(id) {
*component = layer;
} else {
self.push(layer)
self.push(Box::new(layer))
}
}

Expand Down Expand Up @@ -221,10 +221,9 @@ impl Compositor {
}

pub fn find_id<T: 'static>(&mut self, id: &'static str) -> Option<&mut T> {
let type_name = std::any::type_name::<T>();
self.layers
.iter_mut()
.find(|component| component.type_name() == type_name && component.id() == Some(id))
.find(|component| component.id() == Some(id))
.and_then(|component| component.as_any_mut().downcast_mut())
}
}
Expand Down