Closes #39172 This refactors when we resolve UI keybindings in an effort to reduce flickering whilst painting these: Previously, we would always resolve these upon creating the binding. This could lead to cases where the corresponding context was not yet available and no binding could be resolved, even if the binding was then available on the next presented frame. Following that, on the next rerender of whatever requested this keybinding, the keybind for that context would then be found, we would render that and then also win a layout shift in that process, as we went from nothing rendered to something rendered between these frames. With these changes, this now happens less often, because we only look for the keybinding once the context can actually be resolved in the window. | Before | After | | --- | --- | | https://github.com/user-attachments/assets/adebf8ac-217d-4c7f-ae5a-bab3aa0b0ee8 | https://github.com/user-attachments/assets/70a82b4b-488f-4a9f-94d7-b6d0a49aada9 | Also reduced cloning in the keymap editor in this process, since that requiered changing due to this anyway. Release Notes: - Fixed some cases where keybinds would appear with a slight delay, causing a flicker in the process
46 lines
1.3 KiB
Rust
46 lines
1.3 KiB
Rust
use editor::EditorSettings;
|
|
use settings::Settings as _;
|
|
use ui::{ButtonCommon, Clickable, Context, Render, Tooltip, Window, prelude::*};
|
|
use workspace::{ItemHandle, StatusItemView};
|
|
|
|
pub const SEARCH_ICON: IconName = IconName::MagnifyingGlass;
|
|
|
|
pub struct SearchButton;
|
|
|
|
impl SearchButton {
|
|
pub fn new() -> Self {
|
|
Self {}
|
|
}
|
|
}
|
|
|
|
impl Render for SearchButton {
|
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl ui::IntoElement {
|
|
let button = div();
|
|
|
|
if !EditorSettings::get_global(cx).search.button {
|
|
return button.hidden();
|
|
}
|
|
|
|
button.child(
|
|
IconButton::new("project-search-indicator", SEARCH_ICON)
|
|
.icon_size(IconSize::Small)
|
|
.tooltip(|_window, cx| {
|
|
Tooltip::for_action("Project Search", &workspace::DeploySearch::default(), cx)
|
|
})
|
|
.on_click(cx.listener(|_this, _, window, cx| {
|
|
window.dispatch_action(Box::new(workspace::DeploySearch::default()), cx);
|
|
})),
|
|
)
|
|
}
|
|
}
|
|
|
|
impl StatusItemView for SearchButton {
|
|
fn set_active_pane_item(
|
|
&mut self,
|
|
_active_pane_item: Option<&dyn ItemHandle>,
|
|
_window: &mut Window,
|
|
_cx: &mut Context<Self>,
|
|
) {
|
|
}
|
|
}
|