chore: fix menu anchoring to trigger bounds
Rust / build (macos-latest, stable) (push) Canceled after 0s
Rust / build (ubuntu-latest, stable) (push) Canceled after 0s
Rust / build (windows-latest, stable) (push) Canceled after 0s

This commit is contained in:
2026-11-28 14:30:57 +07:00
parent 3c5fb68f7e
commit cf81443411
14 changed files with 239 additions and 185 deletions
+1 -1
View File
@@ -61,8 +61,8 @@ impl AppRoot {
let app = cx.weak_entity();
let panels = cx.new(|cx| PanelStack::new("signed-panel", cx));
let titlebar = cx.new(|cx| TitlebarView::new(app.clone(), window, cx));
let empty = cx.new(|_| PlaceholderView::new("Select a repository"));
panels.update(cx, |panels, cx| {
panels.set_empty(empty, None, cx);
});
+7 -4
View File
@@ -1,7 +1,6 @@
use gpui::{
Context, IntoElement, ParentElement as _, Render, SharedString, Styled as _, Window, div,
};
use gpui::{Context, IntoElement, ParentElement as _, Render, SharedString, Styled as _, Window};
use ui::empty_state::EmptyState;
use ui::layout::v_flex;
/// A tab that stands in for a screen that is not ported yet.
pub struct PlaceholderView {
@@ -18,6 +17,10 @@ impl PlaceholderView {
impl Render for PlaceholderView {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
div().size_full().child(EmptyState::new(self.title.clone()))
v_flex()
.size_full()
.items_center()
.justify_center()
.child(EmptyState::new(self.title.clone()))
}
}
+2
View File
@@ -20,6 +20,7 @@ where
L: Fn(EventId) -> Option<Event>,
{
let resolver = ThreadResolver::new(lookup);
let mut groups: HashMap<EventId, Vec<Event>> = HashMap::new();
for event in events {
if event.pubkey == me {
@@ -46,6 +47,7 @@ where
.map(|root| {
let mut events = groups.remove(&root).unwrap_or_default();
let mut own_events = own_groups.remove(&root).unwrap_or_default();
sort_newest_first(&mut events);
sort_newest_first(&mut own_events);
+1 -1
View File
@@ -72,8 +72,8 @@ impl InboxItem {
.then_with(|| b.id.to_hex().cmp(&a.id.to_hex()))
});
rest.truncate(limit.saturating_sub(events.len()));
events.extend(rest);
events.extend(rest);
events.sort_by_key(|event| event.created_at);
events
}
@@ -47,6 +47,7 @@ impl InboxReadState {
/// Marks all events from other authors within the window as read.
pub fn mark_all_read(&mut self, all: &[Event], me: PublicKey, now: Timestamp) {
let cutoff = now - MARK_ALL_WINDOW;
self.read_before = cutoff;
self.read_ids = all
.iter()
+2
View File
@@ -131,9 +131,11 @@ where
/// Parses a four-value `e` tag carrying the given marker.
fn e_tag_with_marker(&self, tag: &Tag, marker: &str) -> Option<EventId> {
let slice = tag.as_slice();
if tag.kind() != "e" || slice.len() != 4 || slice[3] != marker {
return None;
}
tag.content()
.and_then(|content| EventId::from_hex(content).ok())
}
+11
View File
@@ -24,6 +24,7 @@ impl<'a> PullRequest<'a> {
let Some(tip) = pr.current_commit() else {
return Vec::new();
};
let Some(last) = patches
.iter()
.filter(|patch| Self::patch_produces_commit(patch, &tip))
@@ -35,10 +36,12 @@ impl<'a> PullRequest<'a> {
let mut series = vec![last];
let mut tail = last;
loop {
let Some(prev_id) = tail.tags.event_ids().next() else {
break;
};
let Some(prev) = patches
.iter()
.find(|patch| patch.id == prev_id && !series.contains(patch))
@@ -46,9 +49,11 @@ impl<'a> PullRequest<'a> {
else {
break;
};
series.push(prev);
tail = prev;
}
series.reverse();
series
}
@@ -58,9 +63,11 @@ impl<'a> PullRequest<'a> {
let pr = self.0;
let patches: Vec<&'a Event> = patches.into_iter().collect();
let series = self.patches(patches.iter().copied());
if series.is_empty() {
return pr.content.clone();
}
series
.iter()
.map(|patch| patch.content.as_str())
@@ -89,18 +96,22 @@ impl<'a> PullRequest<'a> {
fn forward_series(root: &'a Event, patches: &[&'a Event]) -> Vec<&'a Event> {
let mut series = vec![root];
let mut tail = root;
loop {
let next = patches
.iter()
.filter(|patch| !series.contains(patch))
.filter(|patch| patch.tags.event_ids().any(|id| id == tail.id))
.max_by_key(|patch| patch.created_at);
let Some(next) = next else {
break;
};
series.push(next);
tail = next;
}
series
}
+1
View File
@@ -17,6 +17,7 @@ impl Upstream {
.ok()
.filter(|coordinate| coordinate.kind == Kind::GitRepoAnnouncement)
.map(RepoAddr::from);
Self {
raw: raw.to_owned(),
addr,
+11 -2
View File
@@ -41,7 +41,7 @@ use crate::components::common::{
};
use crate::components::empty_state::EmptyState;
use crate::components::input::{Input, InputState, InputStateEvent};
use crate::components::menu::anchored_overlay;
use crate::components::menu::{TriggerAnchor, TriggerBoundsCell, anchored_overlay};
use crate::icons::{Icon, IconRole};
use crate::theme::{ActiveTheme as _, COMBOBOX_MIN_WIDTH, COMBOBOX_WIDTH, POPUP_MAX_HEIGHT, Size};
@@ -588,7 +588,13 @@ where
let id = self.id.clone();
let open = self.highlight.is_some();
let weak = cx.weak_entity();
let wrapper_bounds: Rc<RefCell<Option<Bounds<Pixels>>>> = Rc::new(RefCell::new(None));
let wrapper_bounds: TriggerBoundsCell = window
.use_keyed_state((id.clone(), "wrapper-bounds"), cx, |_, _| {
Rc::new(RefCell::new(None)) as TriggerBoundsCell
})
.read(cx)
.clone();
div()
.id(id.clone())
@@ -725,6 +731,9 @@ where
wrapper.child(anchored_overlay(
None,
wrapper_bounds
.borrow()
.map(|bounds| TriggerAnchor::below(window, bounds)),
v_flex()
.id((id.clone(), "panel"))
.debug_selector({
+56 -12
View File
@@ -27,8 +27,8 @@ use std::time::Duration;
use gpui::prelude::FluentBuilder;
use gpui::{
Animation, AnimationExt as _, AnyElement, App, Bounds, DefiniteLength, DispatchPhase, Div,
ElementId, Entity, FocusHandle, Hsla, InteractiveElement as _, IntoElement, KeyBinding,
Anchor, Animation, AnimationExt as _, AnyElement, App, Bounds, DefiniteLength, DispatchPhase,
Div, ElementId, Entity, FocusHandle, Hsla, InteractiveElement as _, IntoElement, KeyBinding,
ListAlignment, ListSizingBehavior, ListState, MouseButton, MouseDownEvent, ParentElement as _,
Pixels, Point, RenderOnce, Role, SharedString, Stateful, StatefulInteractiveElement as _,
StyleRefinement, Styled, Window, actions, anchored, canvas, deferred, div, ease_out_quint,
@@ -368,6 +368,7 @@ impl MenuItem {
.role(Role::MenuItem)
.debug_selector(move || format!("{}-item-{index}", env.debug_prefix))
.flex()
.w_full()
.items_center()
.gap_2()
.h_8()
@@ -608,7 +609,13 @@ impl Styled for Menu {
impl RenderOnce for Menu {
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let (chrome, enter_duration) = MenuChrome::read(cx);
let trigger_bounds: TriggerBoundsCell = Rc::new(RefCell::new(None));
// Keyed so the panel can anchor to bounds captured by the last paint.
let trigger_bounds: TriggerBoundsCell = window
.use_keyed_state((self.id.clone(), "trigger-bounds"), cx, |_, _| {
Rc::new(RefCell::new(None)) as TriggerBoundsCell
})
.read(cx)
.clone();
let on_change = self.on_change.clone();
let panel_focus = ElementId::from((self.id.clone(), "panel")).focus_handle(window, cx);
@@ -706,6 +713,10 @@ impl MenuPanelSpec {
return None;
}
let target = self
.trigger_bounds
.borrow()
.map(|bounds| TriggerAnchor::below(window, bounds));
let state = MenuPanelState::new(id, window, cx);
let panel = state.panel(
window,
@@ -729,7 +740,7 @@ impl MenuPanelSpec {
},
);
Some(anchored_overlay(self.position, panel, None))
Some(anchored_overlay(self.position, target, panel, None))
}
}
@@ -1245,9 +1256,39 @@ pub(crate) fn trigger_toggle(
.inset_0()
}
/// Where an overlay hangs off its trigger.
#[derive(Clone, Copy)]
pub(crate) struct TriggerAnchor {
target: Bounds<Pixels>,
/// The panel's corner that meets the trigger.
anchor: Anchor,
/// The trigger's corner the panel hangs from.
corner: Anchor,
}
impl TriggerAnchor {
/// Hangs the panel below the trigger, aligned to the trigger edge nearer the window's center.
pub(crate) fn below(window: &Window, target: Bounds<Pixels>) -> Self {
if target.center().x > window.viewport_size().width / 2.0 {
Self {
target,
anchor: Anchor::TopRight,
corner: Anchor::BottomRight,
}
} else {
Self {
target,
anchor: Anchor::TopLeft,
corner: Anchor::BottomLeft,
}
}
}
}
/// Deferred anchored overlay on OVERLAY_LAYER, optionally fading in.
pub(crate) fn anchored_overlay<E: IntoElement>(
position: Option<Point<Pixels>>,
trigger: Option<TriggerAnchor>,
panel: E,
fade: Option<(&'static str, Duration)>,
) -> AnyElement {
@@ -1263,14 +1304,17 @@ pub(crate) fn anchored_overlay<E: IntoElement>(
None => div().child(panel).into_any_element(),
};
deferred(
anchored()
.when_some(position, |anchored, position| anchored.position(position))
.offset(point(px(0.), px(4.)))
.child(wrapper),
)
.with_priority(OVERLAY_LAYER)
.into_any_element()
let overlay = match (position, trigger) {
(Some(position), _) => anchored().position(position),
(None, Some(trigger)) => anchored()
.anchor(trigger.anchor)
.attach(trigger.target, trigger.corner),
(None, None) => anchored(),
};
deferred(overlay.offset(point(px(0.), px(4.))).child(wrapper))
.with_priority(OVERLAY_LAYER)
.into_any_element()
}
/// Canvas that grabs focus when `should_grab` holds.
+14 -2
View File
@@ -32,7 +32,8 @@ use gpui::{
use crate::components::common::{ElementIdExt as _, StyledExt as _, v_flex};
use crate::components::dialog::Dismiss;
use crate::components::menu::{
ChangeHandler, TriggerBoundsCell, anchored_overlay, focus_capture, trigger_toggle,
ChangeHandler, TriggerAnchor, TriggerBoundsCell, anchored_overlay, focus_capture,
trigger_toggle,
};
use crate::theme::{ActiveTheme as _, POPOVER_MIN_WIDTH};
@@ -135,7 +136,12 @@ impl RenderOnce for Popover {
)
};
let trigger_bounds: TriggerBoundsCell = Rc::new(RefCell::new(None));
let trigger_bounds: TriggerBoundsCell = window
.use_keyed_state((self.id.clone(), "trigger-bounds"), cx, |_, _| {
Rc::new(RefCell::new(None)) as TriggerBoundsCell
})
.read(cx)
.clone();
// Keyboard focus rides the panel across frames.
let focus = self.id.focus_handle(window, cx);
@@ -163,8 +169,13 @@ impl RenderOnce for Popover {
let label = fallback_label.clone();
let content = self.content.map(|content| content(window, cx));
let target = trigger_bounds
.borrow()
.map(|bounds| TriggerAnchor::below(window, bounds));
wrapper.child(anchored_overlay(
None,
target,
v_flex()
.id((self.id.clone(), "popover-panel"))
.debug_selector(|| "popover-panel".to_string())
@@ -180,6 +191,7 @@ impl RenderOnce for Popover {
.on_mouse_down_out({
let on_change = on_change.clone();
let trigger_bounds = trigger_bounds.clone();
move |event, window, cx| {
if trigger_bounds
.borrow()
+7 -26
View File
@@ -1,13 +1,11 @@
//! Signed's icon set: application-defined SVG glyphs.
use std::borrow::Cow;
use std::time::Duration;
use gpui::prelude::FluentBuilder as _;
use gpui::{
AbsoluteLength, App, AssetSource, Div, Hsla, IntoElement, ParentElement as _, Pixels, Rems,
RenderOnce, Result, SharedString, Styled as _, TimedTransformation, Transformation, Window,
div, rems, svg,
AbsoluteLength, App, Div, Hsla, IntoElement, ParentElement as _, Pixels, Rems, RenderOnce,
SharedString, Styled as _, TimedTransformation, Transformation, Window, div, rems, svg,
};
const SMALL_ICON_SIZE: Rems = rems(0.875);
@@ -16,6 +14,11 @@ const LARGE_ICON_SIZE: Rems = rems(1.25);
/// The spin presents at most this rate, rotating a sprite needs no more frames.
const SPIN_MAX_FPS: f32 = 60.0;
#[derive(rust_embed::RustEmbed)]
#[folder = "src/icons/assets"]
#[exclude = "*.DS_Store"]
pub struct Assets;
/// The semantic glyphs UI components need.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum IconRole {
@@ -313,25 +316,3 @@ impl RenderOnce for Icon {
Self::render_svg_path(size, Some(color), transformation, rotation_period, path)
}
}
#[derive(rust_embed::RustEmbed)]
#[folder = "src/icons/assets"]
#[exclude = "*.DS_Store"]
pub struct Assets;
impl AssetSource for Assets {
fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> {
let name = match path.strip_prefix("icons/") {
Some(name) => name,
None => return Ok(None),
};
Ok(Assets::get(name).map(|file| file.data))
}
fn list(&self, path: &str) -> gpui::Result<Vec<SharedString>> {
Ok(Self::iter()
.map(|file| SharedString::from(format!("icons/{file}")))
.filter(|file| file.starts_with(path))
.collect())
}
}