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
93 lines
2.7 KiB
Rust
93 lines
2.7 KiB
Rust
use editor::{Editor, EditorElement, EditorStyle};
|
|
use gpui::{Action, Entity, FocusHandle, Hsla, IntoElement, TextStyle};
|
|
use settings::Settings;
|
|
use theme::ThemeSettings;
|
|
use ui::{IconButton, IconButtonShape};
|
|
use ui::{Tooltip, prelude::*};
|
|
|
|
pub(super) enum ActionButtonState {
|
|
Disabled,
|
|
Toggled,
|
|
}
|
|
|
|
pub(super) fn render_action_button(
|
|
id_prefix: &'static str,
|
|
icon: ui::IconName,
|
|
button_state: Option<ActionButtonState>,
|
|
tooltip: &'static str,
|
|
action: &'static dyn Action,
|
|
focus_handle: FocusHandle,
|
|
) -> impl IntoElement {
|
|
IconButton::new(
|
|
SharedString::from(format!("{id_prefix}-{}", action.name())),
|
|
icon,
|
|
)
|
|
.shape(IconButtonShape::Square)
|
|
.on_click({
|
|
let focus_handle = focus_handle.clone();
|
|
move |_, window, cx| {
|
|
if !focus_handle.is_focused(window) {
|
|
window.focus(&focus_handle);
|
|
}
|
|
window.dispatch_action(action.boxed_clone(), cx)
|
|
}
|
|
})
|
|
.tooltip(move |_window, cx| Tooltip::for_action_in(tooltip, action, &focus_handle, cx))
|
|
.when_some(button_state, |this, state| match state {
|
|
ActionButtonState::Toggled => this.toggle_state(true),
|
|
ActionButtonState::Disabled => this.disabled(true),
|
|
})
|
|
}
|
|
|
|
pub(crate) fn input_base_styles(border_color: Hsla, map: impl FnOnce(Div) -> Div) -> Div {
|
|
h_flex()
|
|
.map(map)
|
|
.min_w_32()
|
|
.h_8()
|
|
.pl_2()
|
|
.pr_1()
|
|
.py_1()
|
|
.border_1()
|
|
.border_color(border_color)
|
|
.rounded_md()
|
|
}
|
|
|
|
pub(crate) fn render_text_input(
|
|
editor: &Entity<Editor>,
|
|
color_override: Option<Color>,
|
|
app: &App,
|
|
) -> impl IntoElement {
|
|
let (color, use_syntax) = if editor.read(app).read_only(app) {
|
|
(app.theme().colors().text_disabled, false)
|
|
} else {
|
|
match color_override {
|
|
Some(color_override) => (color_override.color(app), false),
|
|
None => (app.theme().colors().text, true),
|
|
}
|
|
};
|
|
|
|
let settings = ThemeSettings::get_global(app);
|
|
let text_style = TextStyle {
|
|
color,
|
|
font_family: settings.buffer_font.family.clone(),
|
|
font_features: settings.buffer_font.features.clone(),
|
|
font_fallbacks: settings.buffer_font.fallbacks.clone(),
|
|
font_size: rems(0.875).into(),
|
|
font_weight: settings.buffer_font.weight,
|
|
line_height: relative(1.3),
|
|
..TextStyle::default()
|
|
};
|
|
|
|
let mut editor_style = EditorStyle {
|
|
background: app.theme().colors().toolbar_background,
|
|
local_player: app.theme().players().local(),
|
|
text: text_style,
|
|
..EditorStyle::default()
|
|
};
|
|
if use_syntax {
|
|
editor_style.syntax = app.theme().syntax().clone();
|
|
}
|
|
|
|
EditorElement::new(editor, editor_style)
|
|
}
|