Interaction · Keys, scroll and focus: roving focus, scroll sync, type-ahead

RovingFocus keeps a row or column of items behind one Tab stop: the
arrows walk focus, Home and End reach the ends, Enter or Space presses,
and a press moves the stop without taking focus. ScrollSync keeps boxes
at one place along an axis: the pane a wheel turned leads, and a canvas
ahead of the panes copies its place before they draw. SelectableList
moves its cursor to the row that starts with the letters typed, the
letters joining within a pause and a Command letter left to the app.
forms::History becomes public as the undo manager. The gallery shows
gpui's own key bindings, a two-stroke chord waiting on its first
stroke, uniform_list, autofocus and the focus ring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-09-27 16:10:32 -04:00
1 parent ec4c15b539
commit 9e3e6c109d
18 files changed
+925 -29

No files matched your search

@@ -1,9 +1,11 @@
use std::time::Duration;
use gpui::{
AppContext, Context, Entity, FocusHandle, InteractiveElement, IntoElement, ParentElement,
Render, TestAppContext, Window, div,
AppContext, Context, Entity, FocusHandle, InteractiveElement, IntoElement, Modifiers,
ParentElement, Render, TestAppContext, Window, div,
};
use super::{enter, settle, setup};
use super::{Picks, enter, picks, row, settle, setup};
use crate::{
buttons::Button,
forms::{Enter, Input, TextInput},
@@ -92,3 +94,44 @@ fn a_release_that_began_elsewhere_opens_nothing(cx: &mut TestAppContext) {
settle(cx);
assert!(view.read_with(cx, |view, _| view.heard.is_empty()));
}
/// Typing a row's first letters moves the cursor there and picks it; after a pause the letters start over.
#[gpui::test]
fn letters_move_to_the_row_that_starts_with_them(cx: &mut TestAppContext) {
setup(cx);
let (view, cx) = cx.add_window_view(|_, _| Picks(Vec::new(), Vec::new(), None, false));
settle(cx);
cx.simulate_click(row(0), Modifiers::none());
settle(cx);
cx.simulate_input("c");
settle(cx);
assert_eq!(picks(&view, cx), ["c"]);
cx.executor().advance_clock(Duration::from_secs(1));
cx.simulate_input("b");
settle(cx);
assert_eq!(
picks(&view, cx),
["b"],
"the pause started the letters over"
);
}
/// A letter held with Command is the app's shortcut, not a letter to move by: Command-A still takes all.
#[gpui::test]
fn a_letter_with_command_stays_a_shortcut(cx: &mut TestAppContext) {
setup(cx);
let (view, cx) = cx.add_window_view(|_, _| Picks(Vec::new(), Vec::new(), None, false));
settle(cx);
cx.simulate_click(row(1), Modifiers::none());
settle(cx);
cx.simulate_event(gpui::KeyDownEvent {
keystroke: gpui::Keystroke {
modifiers: Modifiers::command(),
key: "a".into(),
key_char: Some("a".into()),
},
is_held: false,
});
settle(cx);
assert_eq!(picks(&view, cx), ["a", "b", "c", "d"]);
}
+1 -1
View File
@@ -18,7 +18,7 @@ use crate::{
theme::Theme,
};
mod release;
mod keys;
fn setup(cx: &mut TestAppContext) {
cx.update(|cx| {