1use editor::{Editor, EditorElement, EditorStyle};
2use gpui::{Action, Entity, FocusHandle, Hsla, IntoElement, TextStyle};
3use settings::Settings;
4use theme::ThemeSettings;
5use ui::{IconButton, IconButtonShape};
6use ui::{Tooltip, prelude::*};
7
8pub(super) fn render_action_button(
9 id_prefix: &'static str,
10 icon: ui::IconName,
11 active: bool,
12 tooltip: &'static str,
13 action: &'static dyn Action,
14 focus_handle: FocusHandle,
15) -> impl IntoElement {
16 IconButton::new(
17 SharedString::from(format!("{id_prefix}-{}", action.name())),
18 icon,
19 )
20 .shape(IconButtonShape::Square)
21 .on_click({
22 let focus_handle = focus_handle.clone();
23 move |_, window, cx| {
24 if !focus_handle.is_focused(&window) {
25 window.focus(&focus_handle);
26 }
27 window.dispatch_action(action.boxed_clone(), cx)
28 }
29 })
30 .tooltip(move |window, cx| Tooltip::for_action_in(tooltip, action, &focus_handle, window, cx))
31 .disabled(!active)
32}
33
34pub(crate) fn input_base_styles(border_color: Hsla, map: impl FnOnce(Div) -> Div) -> Div {
35 h_flex()
36 .min_w_32()
37 .map(map)
38 .h_8()
39 .pl_2()
40 .pr_1()
41 .py_1()
42 .border_1()
43 .border_color(border_color)
44 .rounded_lg()
45}
46
47pub(crate) fn render_text_input(
48 editor: &Entity<Editor>,
49 color_override: Option<Color>,
50 app: &App,
51) -> impl IntoElement {
52 let (color, use_syntax) = if editor.read(app).read_only(app) {
53 (app.theme().colors().text_disabled, false)
54 } else {
55 match color_override {
56 Some(color_override) => (color_override.color(app), false),
57 None => (app.theme().colors().text, true),
58 }
59 };
60
61 let settings = ThemeSettings::get_global(app);
62 let text_style = TextStyle {
63 color,
64 font_family: settings.buffer_font.family.clone(),
65 font_features: settings.buffer_font.features.clone(),
66 font_fallbacks: settings.buffer_font.fallbacks.clone(),
67 font_size: rems(0.875).into(),
68 font_weight: settings.buffer_font.weight,
69 line_height: relative(1.3),
70 ..TextStyle::default()
71 };
72
73 let mut editor_style = EditorStyle {
74 background: app.theme().colors().toolbar_background,
75 local_player: app.theme().players().local(),
76 text: text_style,
77 ..EditorStyle::default()
78 };
79 if use_syntax {
80 editor_style.syntax = app.theme().syntax().clone();
81 }
82
83 EditorElement::new(editor, editor_style)
84}