Port · Build: Zed's gpui at 1a28cff
gpui and gpui_platform now come from Zed's repo by git at 1a28cff, the code gpui-pre 0.3.7 republishes, so the gallery can later build for the browser. gpui takes stacker, as 0.2.2 always did, and gpui_platform takes font-kit, without which macOS draws no text; runtime_shaders moves to gpui_platform. The API moved: focus, blur and Tab steps take cx, Corner is Anchor, shaped lines paint with an alignment, defer_draw takes a content mask, the inspector registers a factory, async updates return their value, and wrapped lines are shared, not cloned. Updates through a window context go through the window, so a closed window still ends them as it did. Where the new gpui behaves differently, Ely keeps its old intent. Holds and reveals under a resting pointer survive typing through gpui's input-modality-independent hover; previews the keyboard also moves keep the default, and the calendar's leave ignores a key press. Enter reaches a button inside the code editor, since gpui now arms a key click on the press. The event logger skips a lone modifier. A video and an image grid keep their shape in a flex column under taffy 0.13, as a picture does. AGENTS.md records the new stack and the rules this port changes; the rest of the old gpui and taffy rules are re-tested in T44c. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e49c93bb6f
commit
94deeaed52
199 files changed
+2513
-2643
No files matched your search
@@ -329,7 +329,7 @@ impl RenderOnce for Calendar {
|
||||
.grid_cols(7)
|
||||
.gap_0p5()
|
||||
.on_hover(move |over, window, cx| {
|
||||
if !*over {
|
||||
if !*over && !window.last_input_was_keyboard() {
|
||||
leave.update(cx, |hover, cx| {
|
||||
*hover = None;
|
||||
cx.notify();
|
||||
|
||||
@@ -60,7 +60,7 @@ pub(crate) fn toggle(
|
||||
state.preview = None;
|
||||
cx.notify();
|
||||
});
|
||||
window.focus(if open { &inner } else { trigger });
|
||||
window.focus(if open { &inner } else { trigger }, cx);
|
||||
}
|
||||
|
||||
/// What a picker field shows while closed, and how it sits.
|
||||
|
||||
+3
-1
@@ -110,7 +110,9 @@ impl RenderOnce for InputGroup {
|
||||
.bg(colors.surface)
|
||||
.text_size(theme.text_size(text_size(self.size)))
|
||||
.text_color(colors.fg)
|
||||
.on_mouse_down(MouseButton::Left, move |_, window, _| window.focus(&focus))
|
||||
.on_mouse_down(MouseButton::Left, move |_, window, cx| {
|
||||
window.focus(&focus, cx)
|
||||
})
|
||||
.children(self.before.into_iter().map(|block| addon(block, true)))
|
||||
.child(div().flex_1().min_w_0().px(pad).child(self.state))
|
||||
.children(self.after.into_iter().map(|block| addon(block, false)))
|
||||
|
||||
+2
-2
@@ -73,7 +73,7 @@ impl RenderOnce for HotkeyInput {
|
||||
let bare = !stroke.modifiers.modified();
|
||||
let next = match stroke.key.as_str() {
|
||||
"escape" if bare => {
|
||||
window.blur();
|
||||
window.blur(cx);
|
||||
return;
|
||||
}
|
||||
"backspace" | "delete" if bare => None,
|
||||
@@ -87,7 +87,7 @@ impl RenderOnce for HotkeyInput {
|
||||
next.as_ref()
|
||||
.map_or("cleared".into(), |stroke| stroke.unparse())
|
||||
);
|
||||
window.blur();
|
||||
window.blur(cx);
|
||||
if let Some(on_change) = &on_change {
|
||||
on_change(next, window, cx);
|
||||
}
|
||||
|
||||
+5
-5
@@ -33,7 +33,7 @@ impl Editing {
|
||||
});
|
||||
let all = field.read(cx).text().len();
|
||||
field.update(cx, |input, cx| input.select(0..all, cx));
|
||||
window.focus(&field.read(cx).focus().clone());
|
||||
window.focus(&field.read(cx).focus().clone(), cx);
|
||||
let owner = state.clone();
|
||||
let events = window.subscribe(&field, cx, move |_, event, window, cx| match event {
|
||||
InputEvent::Submit => owner.update(cx, |editing, cx| {
|
||||
@@ -58,10 +58,10 @@ impl Editing {
|
||||
self.back = Some(back);
|
||||
}
|
||||
|
||||
pub(crate) fn give_back(&mut self, window: &mut Window) {
|
||||
pub(crate) fn give_back(&mut self, window: &mut Window, cx: &mut App) {
|
||||
if let Some(back) = self.back.take() {
|
||||
log::info!("inline edit: focus handed back");
|
||||
window.focus(&back);
|
||||
window.focus(&back, cx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ impl RenderOnce for InlineEdit {
|
||||
cx.stop_propagation();
|
||||
escape.update(cx, |editing, cx| {
|
||||
editing.finish(true, window, cx);
|
||||
editing.give_back(window);
|
||||
editing.give_back(window, cx);
|
||||
});
|
||||
}
|
||||
})
|
||||
@@ -143,7 +143,7 @@ impl RenderOnce for InlineEdit {
|
||||
cx.stop_propagation();
|
||||
enter.update(cx, |editing, cx| {
|
||||
editing.finish(false, window, cx);
|
||||
editing.give_back(window);
|
||||
editing.give_back(window, cx);
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
+4
-2
@@ -115,7 +115,9 @@ impl RenderOnce for Input {
|
||||
} else {
|
||||
colors.fg
|
||||
})
|
||||
.on_mouse_down(MouseButton::Left, move |_, window, _| window.focus(&focus))
|
||||
.on_mouse_down(MouseButton::Left, move |_, window, cx| {
|
||||
window.focus(&focus, cx)
|
||||
})
|
||||
.children(self.prefix)
|
||||
.child(div().flex_1().min_w_0().child(self.state))
|
||||
.when(self.clearable && !empty && !disabled, |frame| {
|
||||
@@ -125,7 +127,7 @@ impl RenderOnce for Input {
|
||||
.tooltip("Clear")
|
||||
.on_click(move |_, window, cx| {
|
||||
state.update(cx, |input, cx| input.set_text("", cx));
|
||||
window.focus(&state.read(cx).focus().clone());
|
||||
window.focus(&state.read(cx).focus().clone(), cx);
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use gpui::{
|
||||
Animation, AnimationExt, AnyElement, App, Bounds, Corner, Div, ElementId, Entity,
|
||||
Anchor, Animation, AnimationExt, AnyElement, App, Bounds, Div, ElementId, Entity,
|
||||
InteractiveElement, IntoElement, MouseButton, ParentElement, Pixels, ScrollHandle,
|
||||
SharedString, Stateful, StatefulInteractiveElement, Styled, Window, anchored, canvas, div,
|
||||
prelude::*,
|
||||
@@ -216,7 +216,7 @@ pub(crate) fn float_height(
|
||||
let placed = if up {
|
||||
anchored()
|
||||
.position(anchor.origin)
|
||||
.anchor(Corner::BottomLeft)
|
||||
.anchor(Anchor::BottomLeft)
|
||||
.child(
|
||||
div()
|
||||
.child(content)
|
||||
|
||||
+1
-1
@@ -184,7 +184,7 @@ fn render_rows(id: &ElementId, state: Entity<Rows>, add: &'static str, cx: &App)
|
||||
grow.update(cx, |rows, cx| {
|
||||
rows.push(&[], window, cx);
|
||||
let last = rows.rows.last().expect("just pushed");
|
||||
window.focus(&last[0].0.read(cx).focus().clone());
|
||||
window.focus(&last[0].0.read(cx).focus().clone(), cx);
|
||||
rows.report(window, cx);
|
||||
cx.notify();
|
||||
})
|
||||
|
||||
+2
-2
@@ -150,7 +150,7 @@ pub(crate) fn grid(
|
||||
.capture_action(move |_: &Down, window, cx| {
|
||||
if count > 0 {
|
||||
cx.stop_propagation();
|
||||
window.focus(&into);
|
||||
window.focus(&into, cx);
|
||||
}
|
||||
})
|
||||
.capture_action(move |_: &Enter, window, cx| {
|
||||
@@ -231,7 +231,7 @@ pub(crate) fn grid(
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.track_scroll(scroll)
|
||||
.track_scroll(&scroll)
|
||||
.h(theme.list_max_height());
|
||||
div()
|
||||
.track_focus(&focus)
|
||||
|
||||
+1
-1
@@ -256,7 +256,7 @@ impl RenderOnce for RadioGroup {
|
||||
};
|
||||
cx.stop_propagation();
|
||||
let next = step(&choices, at, by);
|
||||
window.focus(&handles[next]);
|
||||
window.focus(&handles[next], cx);
|
||||
pick(&choices[next].value, window, cx);
|
||||
})
|
||||
.children(radios)
|
||||
|
||||
+1
-1
@@ -238,7 +238,7 @@ impl Track {
|
||||
_ => 0,
|
||||
};
|
||||
grab.update(cx, |grab, _| *grab = index);
|
||||
window.focus(&focus[index]);
|
||||
window.focus(&focus[index], cx);
|
||||
jump(index, next, window, cx);
|
||||
})
|
||||
});
|
||||
|
||||
+3
-1
@@ -229,7 +229,9 @@ impl RenderOnce for TagInput {
|
||||
.bg(colors.surface)
|
||||
.text_size(theme.text_size(TextSize::Base))
|
||||
.text_color(colors.fg)
|
||||
.on_mouse_down(MouseButton::Left, move |_, window, _| window.focus(&focus))
|
||||
.on_mouse_down(MouseButton::Left, move |_, window, cx| {
|
||||
window.focus(&focus, cx)
|
||||
})
|
||||
.capture_action(move |_: &Up, _, cx| {
|
||||
if open {
|
||||
cx.stop_propagation();
|
||||
|
||||
+10
-10
@@ -53,7 +53,7 @@ impl Render for Radios {
|
||||
fn radio_arrows_skip_disabled_choices_and_wrap(cx: &mut TestAppContext) {
|
||||
setup(cx);
|
||||
let (view, cx) = cx.add_window_view(|_, _| Radios { chosen: "a".into() });
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_keystrokes("down");
|
||||
assert_eq!(view.read_with(cx, |view, _| view.chosen.clone()), "c");
|
||||
cx.simulate_keystrokes("down");
|
||||
@@ -84,7 +84,7 @@ impl Render for Picker {
|
||||
fn select_opens_moves_and_picks_from_the_keyboard(cx: &mut TestAppContext) {
|
||||
setup(cx);
|
||||
let (view, cx) = cx.add_window_view(|_, _| Picker { chosen: "a".into() });
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_keystrokes("down down enter");
|
||||
assert_eq!(view.read_with(cx, |view, _| view.chosen.clone()), "b");
|
||||
}
|
||||
@@ -213,7 +213,7 @@ impl Render for Level {
|
||||
fn slider_keys_step_jump_and_reach_the_end(cx: &mut TestAppContext) {
|
||||
setup(cx);
|
||||
let (view, cx) = cx.add_window_view(|_, _| Level { value: 10.0 });
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_keystrokes("right pageup");
|
||||
assert_eq!(view.read_with(cx, |view, _| view.value), 21.0);
|
||||
cx.simulate_keystrokes("end");
|
||||
@@ -242,7 +242,7 @@ impl Render for Agree {
|
||||
fn space_toggles_a_focused_checkbox(cx: &mut TestAppContext) {
|
||||
setup(cx);
|
||||
let (view, cx) = cx.add_window_view(|_, _| Agree { on: false });
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_keystrokes("space");
|
||||
cx.simulate_event(KeyUpEvent {
|
||||
keystroke: Keystroke::parse("space").unwrap(),
|
||||
@@ -254,7 +254,7 @@ fn space_toggles_a_focused_checkbox(cx: &mut TestAppContext) {
|
||||
fn a_disabled_choice_still_leaves_the_group_reachable(cx: &mut TestAppContext) {
|
||||
setup(cx);
|
||||
let (view, cx) = cx.add_window_view(|_, _| Radios { chosen: "b".into() });
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_keystrokes("down");
|
||||
assert_eq!(view.read_with(cx, |view, _| view.chosen.clone()), "c");
|
||||
}
|
||||
@@ -281,7 +281,7 @@ impl Render for Several {
|
||||
fn a_full_enter_press_opens_a_multi_select_and_keeps_it_open(cx: &mut TestAppContext) {
|
||||
setup(cx);
|
||||
let (view, cx) = cx.add_window_view(|_, _| Several { chosen: Vec::new() });
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_keystrokes("enter");
|
||||
release("enter", cx);
|
||||
cx.simulate_keystrokes("enter");
|
||||
@@ -333,7 +333,7 @@ fn typed<'a>(
|
||||
#[gpui::test]
|
||||
fn enter_in_a_combobox_skips_a_disabled_first_row(cx: &mut TestAppContext) {
|
||||
let (view, cx) = typed(None, cx);
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_keystrokes("enter");
|
||||
assert_eq!(
|
||||
view.read_with(cx, |view, _| view.chosen.clone()),
|
||||
@@ -386,7 +386,7 @@ fn a_disabled_rating_ignores_the_arrows(cx: &mut TestAppContext) {
|
||||
value: 2,
|
||||
disabled: false,
|
||||
});
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
view.update(cx, |view, cx| {
|
||||
view.disabled = true;
|
||||
cx.notify();
|
||||
@@ -440,7 +440,7 @@ fn a_shut_select_may_be_empty(cx: &mut TestAppContext) {
|
||||
setup(cx);
|
||||
let (_, cx) = cx.add_window_view(|_, _| Empty(true));
|
||||
cx.run_until_parked();
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
assert!(cx.update(|window, cx| window.focused(cx).is_none()));
|
||||
}
|
||||
|
||||
@@ -469,7 +469,7 @@ fn a_long_choice_keeps_its_list_inside_the_window(cx: &mut TestAppContext) {
|
||||
let (_, cx) = cx.add_window_view(|_, _| Named);
|
||||
cx.simulate_resize(gpui::size(px(280.0), px(600.0)));
|
||||
cx.run_until_parked();
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_keystrokes("enter");
|
||||
release("enter", cx);
|
||||
cx.run_until_parked();
|
||||
|
||||
+54
-14
@@ -1,6 +1,8 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use gpui::{
|
||||
Context, IntoElement, KeyUpEvent, Keystroke, ParentElement, Render, Styled, TestAppContext,
|
||||
Window, div,
|
||||
Context, IntoElement, KeyUpEvent, Keystroke, Modifiers, ParentElement, Render, Styled,
|
||||
TestAppContext, Window, div, point, px,
|
||||
};
|
||||
use jiff::civil::{Date, Time, date, time};
|
||||
|
||||
@@ -38,7 +40,7 @@ fn a_date_picker_opens_and_picks_from_the_keyboard(cx: &mut TestAppContext) {
|
||||
value: Some(date(2026, 9, 10)),
|
||||
disabled: false,
|
||||
});
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_keystrokes("enter right enter");
|
||||
assert_eq!(
|
||||
view.read_with(cx, |view, _| view.value),
|
||||
@@ -70,7 +72,7 @@ impl Render for Span {
|
||||
fn a_range_picker_takes_two_picks_in_either_order(cx: &mut TestAppContext) {
|
||||
setup(cx);
|
||||
let (view, cx) = cx.add_window_view(|_, _| Span { value: None });
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_keystrokes("enter enter left left enter");
|
||||
assert_eq!(
|
||||
view.read_with(cx, |view, _| view.value),
|
||||
@@ -106,7 +108,7 @@ fn a_time_picker_steps_with_the_arrows(cx: &mut TestAppContext) {
|
||||
let (view, cx) = cx.add_window_view(|_, _| Clock {
|
||||
value: Some(time(9, 30, 0, 0)),
|
||||
});
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_keystrokes("enter down down");
|
||||
assert_eq!(
|
||||
view.read_with(cx, |view, _| view.value),
|
||||
@@ -143,7 +145,7 @@ fn a_calendar_refuses_days_past_its_max(cx: &mut TestAppContext) {
|
||||
picked: None,
|
||||
max: Some(TODAY),
|
||||
});
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_keystrokes("right enter");
|
||||
assert_eq!(view.read_with(cx, |view, _| view.picked), None);
|
||||
cx.simulate_keystrokes("left enter");
|
||||
@@ -157,7 +159,7 @@ fn a_picker_disabled_while_open_stops_picking(cx: &mut TestAppContext) {
|
||||
value: Some(date(2026, 9, 10)),
|
||||
disabled: false,
|
||||
});
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_keystrokes("enter");
|
||||
view.update(cx, |view, cx| {
|
||||
view.disabled = true;
|
||||
@@ -177,18 +179,18 @@ fn the_month_buttons_carry_the_cursor(cx: &mut TestAppContext) {
|
||||
picked: None,
|
||||
max: None,
|
||||
});
|
||||
cx.update(|window, _| {
|
||||
window.focus_next();
|
||||
window.focus_next();
|
||||
window.focus_next();
|
||||
cx.update(|window, cx| {
|
||||
window.focus_next(cx);
|
||||
window.focus_next(cx);
|
||||
window.focus_next(cx);
|
||||
});
|
||||
cx.simulate_keystrokes("enter");
|
||||
cx.simulate_event(KeyUpEvent {
|
||||
keystroke: Keystroke::parse("enter").unwrap(),
|
||||
});
|
||||
cx.update(|window, _| {
|
||||
window.focus_prev();
|
||||
window.focus_prev();
|
||||
cx.update(|window, cx| {
|
||||
window.focus_prev(cx);
|
||||
window.focus_prev(cx);
|
||||
});
|
||||
cx.simulate_keystrokes("enter");
|
||||
assert_eq!(
|
||||
@@ -196,3 +198,41 @@ fn the_month_buttons_carry_the_cursor(cx: &mut TestAppContext) {
|
||||
Some(date(2026, 10, 25))
|
||||
);
|
||||
}
|
||||
|
||||
/// A calendar that records every preview it reports.
|
||||
struct Watched {
|
||||
seen: Vec<Option<Date>>,
|
||||
}
|
||||
|
||||
impl Render for Watched {
|
||||
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let view = cx.entity();
|
||||
Calendar::new("watched")
|
||||
.selected(TODAY)
|
||||
.today(TODAY)
|
||||
.on_hover(Rc::new(move |date, _, cx| {
|
||||
view.update(cx, |view, cx| {
|
||||
view.seen.push(date);
|
||||
cx.notify();
|
||||
})
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn keys_keep_the_preview_under_a_resting_pointer(cx: &mut TestAppContext) {
|
||||
setup(cx);
|
||||
let (view, cx) = cx.add_window_view(|_, _| Watched { seen: Vec::new() });
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_mouse_move(point(px(120.0), px(200.0)), None, Modifiers::none());
|
||||
let pointed = view.read_with(cx, |view, _| view.seen.last().copied().flatten());
|
||||
assert!(pointed.is_some(), "the pointer rests on a day");
|
||||
cx.simulate_keystrokes("pagedown");
|
||||
cx.update(|window, _| window.refresh());
|
||||
cx.run_until_parked();
|
||||
assert_eq!(
|
||||
view.read_with(cx, |view, _| view.seen.last().copied().flatten()),
|
||||
Some(date(2026, 10, 25)),
|
||||
"the keyboard's day stays the preview"
|
||||
);
|
||||
}
|
||||
@@ -69,7 +69,7 @@ fn text(field: &Entity<TextInput>, cx: &mut VisualTestContext) -> String {
|
||||
}
|
||||
|
||||
fn focus(field: &Entity<TextInput>, cx: &mut VisualTestContext) {
|
||||
cx.update(|window, cx| window.focus(&field.read(cx).focus().clone()));
|
||||
cx.update(|window, cx| window.focus(&field.read(cx).focus().clone(), cx));
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
@@ -80,7 +80,7 @@ fn tab_reaches_fields_and_skips_disabled_ones(cx: &mut TestAppContext) {
|
||||
let mut order = Vec::new();
|
||||
for _ in 0..2 {
|
||||
order.push(cx.update(|window, cx| {
|
||||
window.focus_next();
|
||||
window.focus_next(cx);
|
||||
fields
|
||||
.iter()
|
||||
.position(|field| field.read(cx).focus().is_focused(window))
|
||||
@@ -96,9 +96,9 @@ fn enter_on_a_clear_button_clears_its_own_field(cx: &mut TestAppContext) {
|
||||
field.update(cx, |input, cx| input.set_text("kept", cx));
|
||||
}
|
||||
cx.run_until_parked();
|
||||
cx.update(|window, _| {
|
||||
window.focus_next();
|
||||
window.focus_next();
|
||||
cx.update(|window, cx| {
|
||||
window.focus_next(cx);
|
||||
window.focus_next(cx);
|
||||
});
|
||||
cx.run_until_parked();
|
||||
cx.simulate_keystrokes("enter");
|
||||
@@ -177,7 +177,7 @@ impl Render for Stepped {
|
||||
fn stepping_starts_from_the_typed_number(cx: &mut TestAppContext) {
|
||||
setup(cx);
|
||||
let (view, cx) = cx.add_window_view(|_, _| Stepped { value: 4.0 });
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_keystrokes("cmd-a");
|
||||
cx.simulate_input("20");
|
||||
cx.simulate_keystrokes("up");
|
||||
@@ -188,7 +188,7 @@ fn stepping_starts_from_the_typed_number(cx: &mut TestAppContext) {
|
||||
fn a_typed_number_reaches_the_owner_before_any_blur(cx: &mut TestAppContext) {
|
||||
setup(cx);
|
||||
let (view, cx) = cx.add_window_view(|_, _| Stepped { value: 100.0 });
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_keystrokes("cmd-a");
|
||||
cx.simulate_input("250");
|
||||
assert_eq!(
|
||||
@@ -224,7 +224,7 @@ fn select_all_then_typing_replaces_the_pin(cx: &mut TestAppContext) {
|
||||
let (view, cx) = cx.add_window_view(|_, _| Pin {
|
||||
code: String::new(),
|
||||
});
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_input("4821");
|
||||
cx.simulate_keystrokes("cmd-a");
|
||||
cx.simulate_input("1234");
|
||||
|
||||
@@ -29,7 +29,7 @@ impl Render for Icons {
|
||||
fn an_icon_is_searched_walked_and_picked_from_the_keyboard(cx: &mut TestAppContext) {
|
||||
setup(cx);
|
||||
let (view, cx) = cx.add_window_view(|_, _| Icons { picked: None });
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_input("arrow down");
|
||||
cx.simulate_keystrokes("down right enter");
|
||||
let wanted: Vec<IconName> = IconName::ALL
|
||||
@@ -135,7 +135,7 @@ fn an_inline_edit_takes_tab_opens_on_enter_and_takes_focus_back(cx: &mut TestApp
|
||||
cx.update(|cx| cx.bind_keys([KeyBinding::new("tab", FocusNext, None)]));
|
||||
let (view, cx) = cx.add_window_view(|_, _| Titled(Vec::new()));
|
||||
cx.update(|window, _| window.activate_window());
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
release("enter", cx);
|
||||
cx.simulate_input("Stairs");
|
||||
release("enter", cx);
|
||||
|
||||
@@ -59,7 +59,7 @@ fn signup(cx: &mut TestAppContext) -> (Entity<Signup>, &mut VisualTestContext) {
|
||||
#[gpui::test]
|
||||
fn cmd_enter_in_a_field_submits_the_form_once(cx: &mut TestAppContext) {
|
||||
let (view, cx) = signup(cx);
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
cx.simulate_input("Ada");
|
||||
cx.simulate_keystrokes("cmd-enter");
|
||||
let counts = view.read_with(cx, |view, _| (view.sent, view.field_submits));
|
||||
@@ -69,9 +69,9 @@ fn cmd_enter_in_a_field_submits_the_form_once(cx: &mut TestAppContext) {
|
||||
#[gpui::test]
|
||||
fn cmd_enter_on_any_control_in_a_form_submits_it(cx: &mut TestAppContext) {
|
||||
let (view, cx) = signup(cx);
|
||||
cx.update(|window, _| {
|
||||
window.focus_next();
|
||||
window.focus_next();
|
||||
cx.update(|window, cx| {
|
||||
window.focus_next(cx);
|
||||
window.focus_next(cx);
|
||||
});
|
||||
cx.simulate_keystrokes("cmd-enter");
|
||||
assert_eq!(
|
||||
@@ -120,16 +120,16 @@ fn field_array_buttons_remove_their_own_row_and_add_one(cx: &mut TestAppContext)
|
||||
let (view, cx) = cx.add_window_view(|_, _| Rows {
|
||||
rows: vec!["a", "b", "c"],
|
||||
});
|
||||
cx.update(|window, _| {
|
||||
window.focus_next();
|
||||
window.focus_next();
|
||||
cx.update(|window, cx| {
|
||||
window.focus_next(cx);
|
||||
window.focus_next(cx);
|
||||
});
|
||||
press("space", cx);
|
||||
assert_eq!(view.read_with(cx, |view, _| view.rows.clone()), ["a", "c"]);
|
||||
cx.update(|window, _| {
|
||||
window.blur();
|
||||
cx.update(|window, cx| {
|
||||
window.blur(cx);
|
||||
for _ in 0..3 {
|
||||
window.focus_next();
|
||||
window.focus_next(cx);
|
||||
}
|
||||
});
|
||||
press("space", cx);
|
||||
|
||||
@@ -56,9 +56,9 @@ fn typing<'a>(
|
||||
tags: Vec::new(),
|
||||
asked: Vec::new(),
|
||||
});
|
||||
cx.update(|window, _| {
|
||||
cx.update(|window, cx| {
|
||||
window.activate_window();
|
||||
window.focus_next();
|
||||
window.focus_next(cx);
|
||||
});
|
||||
settle(cx);
|
||||
cx.simulate_input(words);
|
||||
|
||||
@@ -54,11 +54,11 @@ fn each_row_offers_what_its_state_allows(cx: &mut TestAppContext) {
|
||||
setup(cx);
|
||||
cx.update(|cx| cx.bind_keys([KeyBinding::new("tab", FocusNext, None)]));
|
||||
let (view, cx) = cx.add_window_view(|_, _| Shelf { log: Vec::new() });
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
press("enter", cx);
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
press("enter", cx);
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
press("enter", cx);
|
||||
let log = view.read_with(cx, |shelf, _| shelf.log.clone());
|
||||
assert_eq!(log, ["cancel 0", "retry 1", "remove 2"]);
|
||||
|
||||
@@ -318,7 +318,7 @@ impl TextInput {
|
||||
if self.disabled {
|
||||
return;
|
||||
}
|
||||
window.focus(&self.focus);
|
||||
window.focus(&self.focus, cx);
|
||||
let at = self.offset_for_point(event.position);
|
||||
match event.click_count {
|
||||
2 => {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use gpui::{
|
||||
App, AvailableSpace, Bounds, ContentMask, DispatchPhase, Element, ElementId,
|
||||
ElementInputHandler, Entity, FontStyle, GlobalElementId, Hsla, InspectorElementId, IntoElement,
|
||||
@@ -27,7 +29,7 @@ impl IntoElement for TextElement {
|
||||
}
|
||||
|
||||
pub(crate) struct Prepaint {
|
||||
lines: Vec<(usize, WrappedLine)>,
|
||||
lines: Rc<[(usize, WrappedLine)]>,
|
||||
selections: Vec<Bounds<Pixels>>,
|
||||
caret: Option<Bounds<Pixels>>,
|
||||
selection_color: Hsla,
|
||||
@@ -219,7 +221,8 @@ impl Element for TextElement {
|
||||
.text_system()
|
||||
.shape_text(text.clone().into(), font_size, &runs, wrap, None)
|
||||
.expect("text input shaping failed");
|
||||
let lines: Vec<(usize, WrappedLine)> = line_starts(&text).into_iter().zip(shaped).collect();
|
||||
let lines: Rc<[(usize, WrappedLine)]> =
|
||||
line_starts(&text).into_iter().zip(shaped).collect();
|
||||
let focused = input.focus().is_focused(window);
|
||||
let caret_on = input.caret_on();
|
||||
self.input.update(cx, |input, _| {
|
||||
@@ -285,7 +288,7 @@ impl Element for TextElement {
|
||||
window.with_content_mask(Some(ContentMask { bounds }), |window| {
|
||||
let mut origins = Vec::with_capacity(prepaint.lines.len());
|
||||
let mut top = Pixels::ZERO;
|
||||
for (_, line) in &prepaint.lines {
|
||||
for (_, line) in prepaint.lines.iter() {
|
||||
origins.push(bounds.origin - scroll + point(Pixels::ZERO, top));
|
||||
top += line.size(line_height).height;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ impl TextInput {
|
||||
return Some(Point::default());
|
||||
}
|
||||
let mut top = Pixels::ZERO;
|
||||
for (start, line) in &layout.lines {
|
||||
for (start, line) in layout.lines.iter() {
|
||||
if display <= start + line.len() {
|
||||
let at = line.position_for_index(display - start, layout.line_height)?;
|
||||
return Some(gpui::point(at.x, at.y + top));
|
||||
@@ -82,7 +82,7 @@ impl TextInput {
|
||||
return 0;
|
||||
}
|
||||
let mut top = Pixels::ZERO;
|
||||
for (start, line) in &layout.lines {
|
||||
for (start, line) in layout.lines.iter() {
|
||||
let height = line.size(layout.line_height).height;
|
||||
if local.y < top + height {
|
||||
let inside = gpui::point(local.x.max(Pixels::ZERO), local.y - top);
|
||||
|
||||
@@ -36,7 +36,7 @@ pub(crate) type Fit = Rc<dyn Fn(&str, Range<usize>, &str) -> (String, usize)>;
|
||||
|
||||
/// The last shaped text: one entry per hard line, with its display offset.
|
||||
pub(crate) struct Layout {
|
||||
pub lines: Vec<(usize, WrappedLine)>,
|
||||
pub lines: Rc<[(usize, WrappedLine)]>,
|
||||
pub bounds: Bounds<Pixels>,
|
||||
pub line_height: Pixels,
|
||||
/// The lines show the placeholder, not content.
|
||||
|
||||
Reference in new issue
Block a user