diff --git a/crates/language_tools/src/key_context_view.rs b/crates/language_tools/src/key_context_view.rs index 9eb4d4c7493..612704a485a 100644 --- a/crates/language_tools/src/key_context_view.rs +++ b/crates/language_tools/src/key_context_view.rs @@ -1,10 +1,11 @@ use gpui::{ Action, App, AppContext as _, Entity, EventEmitter, FocusHandle, Focusable, - KeyBindingContextPredicate, KeyContext, Keystroke, MouseButton, Render, Subscription, Task, + KeyBindingContextPredicate, KeyContext, Keystroke, MouseButton, Render, ScrollHandle, + Subscription, Task, }; use itertools::Itertools; use serde_json::json; -use ui::{Button, ButtonStyle}; +use ui::{Button, ButtonStyle, ScrollAxes, Scrollbars, WithScrollbar}; use ui::{ ButtonCommon, Clickable, Context, FluentBuilder, InteractiveElement, Label, LabelCommon, LabelSize, ParentElement, SharedString, StatefulInteractiveElement, Styled, Window, div, @@ -34,6 +35,7 @@ struct KeyContextView { last_possibilities: Vec<(SharedString, SharedString, Option)>, context_stack: Vec, focus_handle: FocusHandle, + scroll_handle: ScrollHandle, _subscriptions: [Subscription; 2], } @@ -101,6 +103,7 @@ impl KeyContextView { }); Self { + scroll_handle: ScrollHandle::new(), context_stack: Vec::new(), pending_keystrokes: None, last_keystrokes: None, @@ -168,10 +171,10 @@ impl Item for KeyContextView { } impl Render for KeyContextView { - fn render(&mut self, _: &mut Window, cx: &mut Context) -> impl ui::IntoElement { + fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl ui::IntoElement { use itertools::Itertools; - let key_equivalents = cx.keyboard_mapper().get_key_equivalents(); + let key_equivalents = cx.keyboard_mapper().get_key_equivalents().cloned(); v_flex() .id("key-context-view") .overflow_scroll() @@ -261,22 +264,41 @@ impl Render for KeyContextView { }) .when_some(self.last_keystrokes.as_ref(), |el, keystrokes| { el.child(Label::new(format!("Typed: {}", keystrokes)).ml_4()) - .children( - self.last_possibilities - .iter() - .map(|(name, predicate, state)| { - let (text, color) = match state { - Some(true) => ("(match)", ui::Color::Success), - Some(false) => ("(low precedence)", ui::Color::Hint), - None => ("(no match)", ui::Color::Error), - }; - h_flex() - .gap_2() - .ml_8() - .child(div().min_w(px(200.)).child(Label::new(name.clone()))) - .child(Label::new(predicate.clone())) - .child(Label::new(text).color(color)) - }), + .child( + div() + .w_full() + .pr_4() + .child( + v_flex() + .id("key-context-possibilities") + .track_scroll(&self.scroll_handle) + .pb_4() + .pl_8() + .overflow_x_scroll() + .items_start() + .children( + self.last_possibilities + .iter() + .map(|(name, predicate, state)| { + let (text, color) = match state { + Some(true) => ("(match)", ui::Color::Success), + Some(false) => ("(low precedence)", ui::Color::Hint), + None => ("(no match)", ui::Color::Error), + }; + h_flex() + .gap_2() + .child(div().min_w(px(200.)).flex_shrink_0().child(Label::new(name.clone()).single_line())) + .child(Label::new(predicate.clone()).single_line().flex_shrink_0()) + .child(Label::new(text).color(color).single_line().flex_shrink_0()) + }), + ) + ) + .custom_scrollbars( + Scrollbars::new(ScrollAxes::Horizontal) + .tracked_scroll_handle(&self.scroll_handle), + window, + cx, + ) ) }) .when_some(key_equivalents, |el, key_equivalents| {