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.
This commit is contained in:
1 parent
25b8a6f22c
commit
4c3ed1bbb9
199 files changed
+2513
-2643
No files matched your search
+1
-1
@@ -248,7 +248,7 @@ impl RenderOnce for MessageEditor {
|
||||
let opened = window.use_keyed_state((self.id.clone(), "opened"), cx, |_, _| false);
|
||||
if !*opened.read(cx) {
|
||||
log::info!("message editor: takes focus");
|
||||
window.focus(&self.field.focus_handle(cx));
|
||||
window.focus(&self.field.focus_handle(cx), cx);
|
||||
opened.update(cx, |opened, _| *opened = true);
|
||||
}
|
||||
let text = self.field.read(cx).text().trim().to_string();
|
||||
|
||||
+19
-16
@@ -15,7 +15,7 @@ use crate::{
|
||||
typography::{Ellipsis, format::file_size},
|
||||
};
|
||||
|
||||
/// A box in a picture's own shape: as wide as the picture, but no wider than `widest` or its container.
|
||||
/// A box in a picture's own shape: as wide as the picture, but no wider than `widest` or its container. Hand it to a flex column inside a block: taffy 0.13 sizes the column by its width before its cap.
|
||||
pub(crate) fn shaped(width: f32, height: f32, widest: Pixels) -> Div {
|
||||
assert!(
|
||||
width > 0.0 && height > 0.0,
|
||||
@@ -76,19 +76,21 @@ impl RenderOnce for ImageMessage {
|
||||
.flex_col()
|
||||
.gap_1()
|
||||
.child(
|
||||
shaped(self.size.0, self.size.1, widest)
|
||||
.id(self.id.clone())
|
||||
.relative()
|
||||
.when_some(open, |picture, open| {
|
||||
picture
|
||||
.cursor_pointer()
|
||||
.on_click(move |_, window, cx| open(window, cx))
|
||||
})
|
||||
.child(
|
||||
Image::new((self.id.clone(), "picture"), source(&self.source))
|
||||
.fit(ObjectFit::Contain)
|
||||
.size_full(),
|
||||
),
|
||||
div().child(
|
||||
shaped(self.size.0, self.size.1, widest)
|
||||
.id(self.id.clone())
|
||||
.relative()
|
||||
.when_some(open, |picture, open| {
|
||||
picture
|
||||
.cursor_pointer()
|
||||
.on_click(move |_, window, cx| open(window, cx))
|
||||
})
|
||||
.child(
|
||||
Image::new((self.id.clone(), "picture"), source(&self.source))
|
||||
.fit(ObjectFit::Contain)
|
||||
.size_full(),
|
||||
),
|
||||
),
|
||||
)
|
||||
.children(self.caption.map(|caption| {
|
||||
div()
|
||||
@@ -183,7 +185,7 @@ impl RenderOnce for ImageGrid {
|
||||
.flex()
|
||||
.flex_col()
|
||||
.gap_0p5();
|
||||
match count {
|
||||
let grid = match count {
|
||||
1 => grid.child(row().child(tile(0))),
|
||||
2 => grid.child(row().child(tile(0)).child(tile(1))),
|
||||
3 => grid.child(
|
||||
@@ -200,7 +202,8 @@ impl RenderOnce for ImageGrid {
|
||||
_ => grid
|
||||
.child(row().child(tile(0)).child(tile(1)))
|
||||
.child(row().child(tile(2)).child(tile(3))),
|
||||
}
|
||||
};
|
||||
div().child(grid)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -249,7 +249,7 @@ impl RenderOnce for VideoMessage {
|
||||
};
|
||||
let playing = self.playing;
|
||||
let toggle = self.on_toggle.clone();
|
||||
shaped(self.size.0, self.size.1, widest)
|
||||
let video = shaped(self.size.0, self.size.1, widest)
|
||||
.id(self.id.clone())
|
||||
.relative()
|
||||
.bg(colors.media_backdrop)
|
||||
@@ -316,6 +316,7 @@ impl RenderOnce for VideoMessage {
|
||||
.bg(colors.on_media.opacity(0.25))
|
||||
.child(div().h_full().w(relative(share)).bg(colors.on_media)),
|
||||
),
|
||||
)
|
||||
);
|
||||
div().child(video)
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ fn citations_and_sources_open_from_the_keyboard(cx: &mut TestAppContext) {
|
||||
});
|
||||
cx.update(|window, _| window.activate_window());
|
||||
settle(cx);
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
release("enter", cx);
|
||||
assert_eq!(
|
||||
cited.read_with(cx, |cited, _| cited.opened),
|
||||
@@ -86,7 +86,7 @@ fn citations_and_sources_open_from_the_keyboard(cx: &mut TestAppContext) {
|
||||
"the badge opens its source"
|
||||
);
|
||||
let folded = frame.borrow().expect("the list is laid out").size.height;
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
release("space", cx);
|
||||
let open = frame.borrow().expect("the list is laid out").size.height;
|
||||
assert!(
|
||||
@@ -126,9 +126,9 @@ fn cards_open_from_the_keyboard(cx: &mut TestAppContext) {
|
||||
let (cards, cx) = cx.add_window_view(|_, _| Cards { opened: Vec::new() });
|
||||
cx.update(|window, _| window.activate_window());
|
||||
settle(cx);
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
release("enter", cx);
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
release("enter", cx);
|
||||
assert_eq!(
|
||||
cards.read_with(cx, |cards, _| cards.opened.clone()),
|
||||
|
||||
@@ -67,7 +67,7 @@ fn open(
|
||||
cx.update(|window, cx| {
|
||||
window.activate_window();
|
||||
let field = compose.read(cx).field.focus_handle(cx);
|
||||
window.focus(&field);
|
||||
window.focus(&field, cx);
|
||||
});
|
||||
settle(cx);
|
||||
(compose, cx)
|
||||
|
||||
@@ -67,9 +67,9 @@ fn a_rows_actions_open_from_the_keyboard(cx: &mut TestAppContext) {
|
||||
let (row, cx) = row(cx);
|
||||
cx.simulate_mouse_move(point(px(10.0), px(200.0)), None, Modifiers::none());
|
||||
settle(cx);
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
settle(cx);
|
||||
cx.update(|window, _| window.focus_next());
|
||||
cx.update(|window, cx| window.focus_next(cx));
|
||||
settle(cx);
|
||||
press("enter", cx);
|
||||
press("enter", cx);
|
||||
|
||||
+66
-9
@@ -1,10 +1,10 @@
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use std::{cell::RefCell, rc::Rc, time::Duration};
|
||||
|
||||
use gpui::{
|
||||
AppContext as _, Bounds, Context, Entity, Focusable, InteractiveElement, IntoElement,
|
||||
KeyUpEvent, Keystroke, Modifiers, MouseButton, ParentElement, Pixels, Render, ScrollDelta,
|
||||
ScrollWheelEvent, Styled, TestAppContext, TouchPhase, VisualTestContext, Window, canvas, div,
|
||||
point, px,
|
||||
AnyElement, AppContext as _, Bounds, Context, Entity, Focusable, InteractiveElement,
|
||||
IntoElement, KeyUpEvent, Keystroke, Modifiers, MouseButton, ParentElement, Pixels, Render,
|
||||
ScrollDelta, ScrollWheelEvent, Styled, TestAppContext, TouchPhase, VisualTestContext, Window,
|
||||
canvas, div, point, px,
|
||||
};
|
||||
|
||||
mod cite;
|
||||
@@ -13,8 +13,8 @@ mod history;
|
||||
mod welcome;
|
||||
|
||||
use super::{
|
||||
DateSeparator, ImageMessage, MessageAvatar, MessageBubble, MessageEditor, MessageList, Role,
|
||||
ThinkingBlock,
|
||||
DateSeparator, ImageGrid, ImageMessage, MessageAvatar, MessageBubble, MessageEditor,
|
||||
MessageList, Role, ThinkingBlock, VideoMessage,
|
||||
};
|
||||
use crate::{forms, forms::TextInput, theme::Theme};
|
||||
|
||||
@@ -139,7 +139,7 @@ fn an_edit_saves_only_a_change_and_escape_cancels(cx: &mut TestAppContext) {
|
||||
cx.update(|window, cx| {
|
||||
window.activate_window();
|
||||
let field = edit.read(cx).field.focus_handle(cx);
|
||||
window.focus(&field);
|
||||
window.focus(&field, cx);
|
||||
});
|
||||
settle(cx);
|
||||
cx.simulate_keystrokes("cmd-enter");
|
||||
@@ -306,6 +306,63 @@ fn a_picture_fits_a_narrow_column_in_its_own_shape(cx: &mut TestAppContext) {
|
||||
assert_eq!(bounds.size.height, px(160.0), "240 wide at 3:2 is 160 tall");
|
||||
}
|
||||
|
||||
/// A message in a narrow flex column, the column measured.
|
||||
struct Column {
|
||||
frame: Measured,
|
||||
message: fn() -> AnyElement,
|
||||
}
|
||||
|
||||
impl Render for Column {
|
||||
fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
|
||||
let frame = self.frame.clone();
|
||||
div().size_full().child(
|
||||
div()
|
||||
.w(px(240.0))
|
||||
.relative()
|
||||
.flex()
|
||||
.flex_col()
|
||||
.child((self.message)())
|
||||
.child(
|
||||
canvas(
|
||||
move |bounds, _, _| *frame.borrow_mut() = Some(bounds),
|
||||
|_, _, _, _| {},
|
||||
)
|
||||
.absolute()
|
||||
.top_0()
|
||||
.left_0()
|
||||
.size_full(),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn column_height(message: fn() -> AnyElement, cx: &mut TestAppContext) -> Pixels {
|
||||
let frame = Measured::default();
|
||||
let seen = frame.clone();
|
||||
let (_, cx) = cx.add_window_view(move |_, _| Column {
|
||||
frame: seen,
|
||||
message,
|
||||
});
|
||||
settle(cx);
|
||||
frame.borrow().expect("the column is laid out").size.height
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn a_video_and_a_grid_fit_a_narrow_flex_column_in_their_shape(cx: &mut TestAppContext) {
|
||||
cx.update(Theme::init);
|
||||
let video = || {
|
||||
VideoMessage::new("video", "dunes.jpg", 960.0, 640.0, Duration::from_secs(84))
|
||||
.into_any_element()
|
||||
};
|
||||
assert_eq!(column_height(video, cx), px(160.0), "240 wide at 3:2");
|
||||
let grid = || ImageGrid::new("grid", ["a.jpg", "b.jpg"]).into_any_element();
|
||||
assert_eq!(
|
||||
column_height(grid, cx),
|
||||
px(120.0),
|
||||
"two side by side at 2:1"
|
||||
);
|
||||
}
|
||||
|
||||
/// Reasoning folded under its time, the block's box measured.
|
||||
struct Reasoning {
|
||||
frame: Measured,
|
||||
@@ -350,7 +407,7 @@ fn the_reasoning_opens_from_the_keyboard(cx: &mut TestAppContext) {
|
||||
cx.update(|window, _| window.activate_window());
|
||||
settle(cx);
|
||||
let closed = frame.borrow().expect("the block is laid out").size.height;
|
||||
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").expect("space parses"),
|
||||
|
||||
Reference in new issue
Block a user