Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/fluent-primitives/src/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions crates/fluent-primitives/src/combobox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -219,7 +219,7 @@ impl Combobox {
}

fn handle_key(&mut self, ev: &KeyDownEvent, window: &mut Window, cx: &mut Context<Self>) {
if crate::focus::handle_tab_navigation(ev, window) {
if crate::focus::handle_tab_navigation(ev, window, cx) {
cx.notify();
return;
}
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand All @@ -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::*;

Expand Down
10 changes: 5 additions & 5 deletions crates/fluent-primitives/src/date_time_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -469,7 +469,7 @@ impl DateTimePicker {
}

fn handle_key(&mut self, ev: &KeyDownEvent, window: &mut Window, cx: &mut Context<Self>) {
if crate::focus::handle_tab_navigation(ev, window) {
if crate::focus::handle_tab_navigation(ev, window, cx) {
cx.notify();
return;
}
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions crates/fluent-primitives/src/dropdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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),
Expand All @@ -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::*;

Expand Down
14 changes: 7 additions & 7 deletions crates/fluent-primitives/src/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
24 changes: 24 additions & 0 deletions crates/fluent-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Corner> 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;
Expand Down
4 changes: 2 additions & 2 deletions crates/fluent-primitives/src/searchbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Searchbox {
}

fn handle_key(&mut self, ev: &KeyDownEvent, window: &mut Window, cx: &mut Context<Self>) {
if crate::focus::handle_tab_navigation(ev, window) {
if crate::focus::handle_tab_navigation(ev, window, cx) {
cx.notify();
return;
}
Expand Down Expand Up @@ -122,7 +122,7 @@ impl Searchbox {
return;
}
let handle = self.focus_handle(cx);
window.focus(&handle);
window.focus(&handle, cx);
cx.notify();
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/fluent-primitives/src/suggestion_popover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Fn(SuggestionItem, &ClickEvent, &mut Window, &mut App) + 'static>;
Expand Down Expand Up @@ -133,7 +133,7 @@ pub struct SuggestionPopover {
open: bool,
exiting: bool,
position: Point<gpui::Pixels>,
anchor: Corner,
anchor: crate::Corner,
items: Vec<SuggestionItem>,
highlighted: Option<usize>,
empty_text: SharedString,
Expand All @@ -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(),
Expand All @@ -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
}
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion crates/fluent-primitives/src/text_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 11 additions & 4 deletions crates/fluent-primitives/src/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl TextInput {
}

fn handle_key(&mut self, ev: &KeyDownEvent, window: &mut Window, cx: &mut Context<Self>) {
if crate::focus::handle_tab_navigation(ev, window) {
if crate::focus::handle_tab_navigation(ev, window, cx) {
cx.notify();
return;
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions crates/fluent-primitives/src/textarea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Textarea {
}

fn handle_key(&mut self, ev: &KeyDownEvent, window: &mut Window, cx: &mut Context<Self>) {
if crate::focus::handle_tab_navigation(ev, window) {
if crate::focus::handle_tab_navigation(ev, window, cx) {
cx.notify();
return;
}
Expand Down Expand Up @@ -166,7 +166,7 @@ impl Textarea {
}

let focus_handle = self.focus_handle(cx);
window.focus(&focus_handle);
window.focus(&focus_handle, cx);
cx.notify();
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/fluent-primitives/src/token_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions docs/gpui-api-drift.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Loading