From 62acd36ceca60ba0c4b515d70c488c36ff08fa3b Mon Sep 17 00:00:00 2001 From: Dino Date: Mon, 9 Nov 2026 11:49:00 +0000 Subject: [PATCH] language_tools: Allow horizontal scrolling on key context view (#66528) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Update `dev: open key context view` in order to add a horizontal scrollbar to the view, as longer predicates could end up hidden if there wasn't enough width to display them in the view. Closes #66044 ## Testing Tested manually, as shown in the recordings below ▼
Before https://github.com/user-attachments/assets/85c43b53-e6d7-4b2f-8499-4800a7ac5c33
After https://github.com/user-attachments/assets/b07b3247-9e72-49c8-8768-5964cc57b21f
## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [x] UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). - [x] Tests cover the new or changed behavior. Release Notes: - Improved `dev: open key context view` in order to allow scrolling through the results list --- crates/language_tools/src/key_context_view.rs | 62 +++++++++++++------ 1 file changed, 42 insertions(+), 20 deletions(-) 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| {