diff --git a/crates/fluent-primitives/src/chip.rs b/crates/fluent-primitives/src/chip.rs index 549cd19..2801cfb 100644 --- a/crates/fluent-primitives/src/chip.rs +++ b/crates/fluent-primitives/src/chip.rs @@ -2,6 +2,7 @@ use fluent_core::ThemeProvider as _; use gpui::{ div, prelude::*, px, App, ClickEvent, ElementId, IntoElement, RenderOnce, SharedString, Window, }; +use std::sync::Arc; /// A dismissable tag / token chip. #[allow(clippy::type_complexity)] @@ -57,7 +58,7 @@ impl RenderOnce for Chip { .child(self.label); if has_dismiss { - let dismiss_id = ElementId::NamedChild(Box::new(self.id), "dismiss".into()); + let dismiss_id = ElementId::NamedChild(Arc::new(self.id), "dismiss".into()); el = el.child( div() .id(dismiss_id) diff --git a/crates/fluent-primitives/src/combobox.rs b/crates/fluent-primitives/src/combobox.rs index 4843885..962e1e0 100644 --- a/crates/fluent-primitives/src/combobox.rs +++ b/crates/fluent-primitives/src/combobox.rs @@ -3,8 +3,8 @@ use std::sync::{Arc, Mutex}; use fluent_core::{Theme, ThemeProvider as _}; use gpui::{ anchored, canvas, deferred, div, point, prelude::*, px, svg, App, Bounds, ClickEvent, Context, - Corner, CursorStyle, FocusHandle, Focusable, IntoElement, KeyDownEvent, MouseButton, - MouseDownEvent, Pixels, Point, Render, SharedString, Window, + CursorStyle, FocusHandle, Focusable, IntoElement, KeyDownEvent, MouseButton, MouseDownEvent, + Pixels, Point, Render, SharedString, Window, }; #[derive(Clone, Debug)] @@ -219,7 +219,7 @@ impl Combobox { } fn handle_key(&mut self, ev: &KeyDownEvent, window: &mut Window, cx: &mut Context) { - if crate::focus::handle_tab_navigation(ev, window) { + if crate::focus::handle_tab_navigation(ev, window, cx) { cx.notify(); return; } @@ -275,7 +275,7 @@ impl Combobox { return; } let handle = self.focus_handle(cx); - window.focus(&handle); + window.focus(&handle, cx); self.update_origin(point( ev.position.x, ev.position.y + px(cx.theme().components.dropdown_height), @@ -480,7 +480,7 @@ impl Render for Combobox { root = root.child(deferred( anchored() - .anchor(Corner::TopLeft) + .anchor(crate::Corner::TopLeft.into()) .position(self.drop_origin) .snap_to_window() .child(list), @@ -504,7 +504,7 @@ mod tests { use std::time::Duration; use fluent_test_utils::init_fluent_test; - use gpui::{AppContext as _, TestAppContext}; + use gpui::TestAppContext; use super::*; diff --git a/crates/fluent-primitives/src/date_time_picker.rs b/crates/fluent-primitives/src/date_time_picker.rs index 0aadb5f..e6b1c27 100644 --- a/crates/fluent-primitives/src/date_time_picker.rs +++ b/crates/fluent-primitives/src/date_time_picker.rs @@ -3,8 +3,8 @@ use std::sync::{Arc, Mutex}; use fluent_core::{Theme, ThemeProvider as _}; use gpui::{ anchored, canvas, deferred, div, point, prelude::*, px, svg, App, Bounds, ClickEvent, Context, - Corner, CursorStyle, FocusHandle, Focusable, FontWeight, IntoElement, KeyDownEvent, - MouseButton, MouseDownEvent, Pixels, Point, Render, SharedString, Window, + CursorStyle, FocusHandle, Focusable, FontWeight, IntoElement, KeyDownEvent, MouseButton, + MouseDownEvent, Pixels, Point, Render, SharedString, Window, }; const MIN_YEAR: i32 = 1; @@ -469,7 +469,7 @@ impl DateTimePicker { } fn handle_key(&mut self, ev: &KeyDownEvent, window: &mut Window, cx: &mut Context) { - if crate::focus::handle_tab_navigation(ev, window) { + if crate::focus::handle_tab_navigation(ev, window, cx) { cx.notify(); return; } @@ -508,7 +508,7 @@ impl DateTimePicker { } let handle = self.focus_handle(cx); - window.focus(&handle); + window.focus(&handle, cx); self.update_origin(point( ev.position.x, ev.position.y + px(cx.theme().components.dropdown_height), @@ -697,7 +697,7 @@ impl Render for DateTimePicker { root = root.child(deferred( anchored() - .anchor(Corner::TopLeft) + .anchor(crate::Corner::TopLeft.into()) .position(self.drop_origin) .snap_to_window() .child(panel), diff --git a/crates/fluent-primitives/src/dropdown.rs b/crates/fluent-primitives/src/dropdown.rs index 2b3a8be..4730f38 100644 --- a/crates/fluent-primitives/src/dropdown.rs +++ b/crates/fluent-primitives/src/dropdown.rs @@ -3,7 +3,7 @@ use std::sync::{Arc, Mutex}; use fluent_core::{Theme, ThemeProvider as _}; use gpui::{ anchored, canvas, deferred, div, point, prelude::*, px, svg, App, Bounds, ClickEvent, Context, - Corner, ElementId, IntoElement, Pixels, Point, Render, SharedString, Window, + ElementId, IntoElement, Pixels, Point, Render, SharedString, Window, }; #[derive(Clone, Debug)] @@ -341,7 +341,7 @@ impl Render for Dropdown { el = el.child(deferred( anchored() - .anchor(Corner::TopLeft) + .anchor(crate::Corner::TopLeft.into()) .position(self.drop_origin) .snap_to_window() .child(list), @@ -357,7 +357,7 @@ mod tests { use std::time::Duration; use fluent_test_utils::init_fluent_test; - use gpui::{AppContext as _, TestAppContext}; + use gpui::TestAppContext; use super::*; diff --git a/crates/fluent-primitives/src/focus.rs b/crates/fluent-primitives/src/focus.rs index 38123d1..c81f784 100644 --- a/crates/fluent-primitives/src/focus.rs +++ b/crates/fluent-primitives/src/focus.rs @@ -9,23 +9,23 @@ pub fn install_focus_keybindings(cx: &mut App) { ]); } -pub(crate) fn focus_next(_: &FocusNextControl, window: &mut Window, _: &mut App) { - window.focus_next(); +pub(crate) fn focus_next(_: &FocusNextControl, window: &mut Window, cx: &mut App) { + window.focus_next(cx); } -pub(crate) fn focus_previous(_: &FocusPreviousControl, window: &mut Window, _: &mut App) { - window.focus_prev(); +pub(crate) fn focus_previous(_: &FocusPreviousControl, window: &mut Window, cx: &mut App) { + window.focus_prev(cx); } -pub(crate) fn handle_tab_navigation(ev: &KeyDownEvent, window: &mut Window) -> bool { +pub(crate) fn handle_tab_navigation(ev: &KeyDownEvent, window: &mut Window, cx: &mut App) -> bool { if ev.keystroke.key != "tab" { return false; } if ev.keystroke.modifiers.shift { - window.focus_prev(); + window.focus_prev(cx); } else { - window.focus_next(); + window.focus_next(cx); } true } diff --git a/crates/fluent-primitives/src/lib.rs b/crates/fluent-primitives/src/lib.rs index 96e1b92..c983b7c 100644 --- a/crates/fluent-primitives/src/lib.rs +++ b/crates/fluent-primitives/src/lib.rs @@ -56,6 +56,30 @@ pub use spinner::Spinner; pub use suggestion_popover::{ SuggestionItem, SuggestionKeyAction, SuggestionListState, SuggestionPopover, }; + +/// The reference corner a popover anchors to. +/// +/// Upstream gpui dropped its `Corner` enum and replaced it with `Anchor`, +/// which adds centre edges. This keeps the four-corner public API the rest of +/// the crates already use, and converts into `gpui::Anchor` at the call site. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Corner { + TopLeft, + TopRight, + BottomLeft, + BottomRight, +} + +impl From for gpui::Anchor { + fn from(corner: Corner) -> Self { + match corner { + Corner::TopLeft => gpui::Anchor::TopLeft, + Corner::TopRight => gpui::Anchor::TopRight, + Corner::BottomLeft => gpui::Anchor::BottomLeft, + Corner::BottomRight => gpui::Anchor::BottomRight, + } + } +} pub use switch::Switch; pub use text_ext::FluentTextExt; pub use text_input::TextInput; diff --git a/crates/fluent-primitives/src/searchbox.rs b/crates/fluent-primitives/src/searchbox.rs index 4565b7c..ecc3160 100644 --- a/crates/fluent-primitives/src/searchbox.rs +++ b/crates/fluent-primitives/src/searchbox.rs @@ -82,7 +82,7 @@ impl Searchbox { } fn handle_key(&mut self, ev: &KeyDownEvent, window: &mut Window, cx: &mut Context) { - if crate::focus::handle_tab_navigation(ev, window) { + if crate::focus::handle_tab_navigation(ev, window, cx) { cx.notify(); return; } @@ -122,7 +122,7 @@ impl Searchbox { return; } let handle = self.focus_handle(cx); - window.focus(&handle); + window.focus(&handle, cx); cx.notify(); } } diff --git a/crates/fluent-primitives/src/suggestion_popover.rs b/crates/fluent-primitives/src/suggestion_popover.rs index ea4c6aa..af87d87 100644 --- a/crates/fluent-primitives/src/suggestion_popover.rs +++ b/crates/fluent-primitives/src/suggestion_popover.rs @@ -2,8 +2,8 @@ use std::sync::Arc; use fluent_core::ThemeProvider as _; use gpui::{ - anchored, deferred, div, prelude::*, px, App, ClickEvent, Corner, IntoElement, MouseDownEvent, - Point, RenderOnce, SharedString, Window, + anchored, deferred, div, prelude::*, px, App, ClickEvent, IntoElement, MouseDownEvent, Point, + RenderOnce, SharedString, Window, }; type SelectHandler = Arc; @@ -133,7 +133,7 @@ pub struct SuggestionPopover { open: bool, exiting: bool, position: Point, - anchor: Corner, + anchor: crate::Corner, items: Vec, highlighted: Option, empty_text: SharedString, @@ -151,7 +151,7 @@ impl SuggestionPopover { open: true, exiting: false, position, - anchor: Corner::TopLeft, + anchor: crate::Corner::TopLeft, items: Vec::new(), highlighted: None, empty_text: "No suggestions".into(), @@ -174,7 +174,7 @@ impl SuggestionPopover { self } - pub fn anchor(mut self, anchor: Corner) -> Self { + pub fn anchor(mut self, anchor: crate::Corner) -> Self { self.anchor = anchor; self } @@ -387,7 +387,7 @@ impl RenderOnce for SuggestionPopover { div().child(deferred( anchored() - .anchor(self.anchor) + .anchor(self.anchor.into()) .position(self.position) .snap_to_window() .child(list), diff --git a/crates/fluent-primitives/src/text_ext.rs b/crates/fluent-primitives/src/text_ext.rs index d512e7f..2134dc8 100644 --- a/crates/fluent-primitives/src/text_ext.rs +++ b/crates/fluent-primitives/src/text_ext.rs @@ -13,7 +13,7 @@ pub trait FluentTextExt: Styled + Sized { /// jiggle horizontally as the values change. Idempotent: calling twice /// only sets the feature once. fn tabular_nums(mut self) -> Self { - let style = self.text_style().get_or_insert_with(Default::default); + let style = self.text_style(); let mut features: Vec<(String, u32)> = style .font_features .as_ref() diff --git a/crates/fluent-primitives/src/text_input.rs b/crates/fluent-primitives/src/text_input.rs index 8c28a55..1ac35b0 100644 --- a/crates/fluent-primitives/src/text_input.rs +++ b/crates/fluent-primitives/src/text_input.rs @@ -273,7 +273,7 @@ impl TextInput { } fn handle_key(&mut self, ev: &KeyDownEvent, window: &mut Window, cx: &mut Context) { - if crate::focus::handle_tab_navigation(ev, window) { + if crate::focus::handle_tab_navigation(ev, window, cx) { cx.notify(); return; } @@ -382,7 +382,7 @@ impl TextInput { return; } let focus_handle = self.focus_handle(cx); - window.focus(&focus_handle); + window.focus(&focus_handle, cx); self.is_selecting = true; if event.modifiers.shift { @@ -745,8 +745,15 @@ impl Element for TextElement { window.paint_quad(selection); } let line = prepaint.line.take().unwrap(); - line.paint(bounds.origin, window.line_height(), window, cx) - .unwrap(); + line.paint( + bounds.origin, + window.line_height(), + gpui::TextAlign::Left, + None, + window, + cx, + ) + .unwrap(); if focus_handle.is_focused(window) && !disabled { if let Some(cursor) = prepaint.cursor.take() { diff --git a/crates/fluent-primitives/src/textarea.rs b/crates/fluent-primitives/src/textarea.rs index e777009..d6e162d 100644 --- a/crates/fluent-primitives/src/textarea.rs +++ b/crates/fluent-primitives/src/textarea.rs @@ -87,7 +87,7 @@ impl Textarea { } fn handle_key(&mut self, ev: &KeyDownEvent, window: &mut Window, cx: &mut Context) { - if crate::focus::handle_tab_navigation(ev, window) { + if crate::focus::handle_tab_navigation(ev, window, cx) { cx.notify(); return; } @@ -166,7 +166,7 @@ impl Textarea { } let focus_handle = self.focus_handle(cx); - window.focus(&focus_handle); + window.focus(&focus_handle, cx); cx.notify(); } } diff --git a/crates/fluent-primitives/src/token_input.rs b/crates/fluent-primitives/src/token_input.rs index 8ccf02c..71771c3 100644 --- a/crates/fluent-primitives/src/token_input.rs +++ b/crates/fluent-primitives/src/token_input.rs @@ -340,7 +340,7 @@ impl TokenInput { return; } - if crate::focus::handle_tab_navigation(ev, window) { + if crate::focus::handle_tab_navigation(ev, window, cx) { cx.notify(); return; } @@ -408,7 +408,7 @@ impl TokenInput { return; } let handle = self.focus_handle(cx); - window.focus(&handle); + window.focus(&handle, cx); self.update_origin(point( ev.position.x, ev.position.y + px(cx.theme().components.dropdown_height), diff --git a/docs/gpui-api-drift.md b/docs/gpui-api-drift.md index 9eb3a9e..fba297d 100644 --- a/docs/gpui-api-drift.md +++ b/docs/gpui-api-drift.md @@ -154,3 +154,4 @@ signature diff. The rows known to matter are called out under "Notes". | Crate | Item | Result | |---|---|---| | `fluent-core` | WI-1425 | No source change. Every symbol it imports is in "unchanged" above, and `cargo check`, `cargo test` (22 unit tests) and `cargo clippy --no-deps -D warnings` pass against `vendor/zed` with the public API untouched. | +| `fluent-primitives` | WI-1426 | Compiles, 27 unit tests pass, `cargo clippy --all-targets --no-deps -D warnings` is clean. The location check above missed five signature changes, all forced by the vendored gpui and each a mechanical adaptation: `Window::focus`, `focus_next` and `focus_prev` now take `&mut App`; `ShapedLine::paint` takes a `TextAlign` and an optional align width (passed `Left` and `None`, the previous implicit behaviour); `Styled::text_style()` returns the refinement directly instead of an `Option`; `ElementId::NamedChild` holds an `Arc` instead of a `Box`; and `Corner` is gone, replaced by `gpui::Anchor`. The crate re-exports its own four-variant `Corner` that converts into `Anchor`, so the popover anchor API the later crates use does not change. |