Improve code context menu layout position esp visual stability (#22102)

* Now decides whether the menu is above or below the target position
before rendering it. This causes its position to no longer vary
depending on the length of completions

* When the text area is height constrained (< 12) lines, now chooses the
side which has the most space. Before it would always display above if
height constrained below.

* Misc code cleanups

Release Notes:

- Improved completions menu layout to be more stable and use available
space better.
This commit is contained in:
Michael Sloan 2024-12-16 23:17:36 -07:00 committed by GitHub
parent fc5a810408
commit a062c0f1bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 155 additions and 93 deletions

View file

@ -3,10 +3,13 @@
use crate::prelude::*;
use crate::v_flex;
use gpui::{
div, AnyElement, Element, IntoElement, ParentElement, RenderOnce, Styled, WindowContext,
div, AnyElement, Element, IntoElement, ParentElement, Pixels, RenderOnce, Styled, WindowContext,
};
use smallvec::SmallVec;
/// Y height added beyond the size of the contents.
pub const POPOVER_Y_PADDING: Pixels = px(8.);
/// A popover is used to display a menu or show some options.
///
/// Clicking the element that launches the popover should not change the current view,
@ -45,7 +48,12 @@ impl RenderOnce for Popover {
div()
.flex()
.gap_1()
.child(v_flex().elevation_2(cx).py_1().children(self.children))
.child(
v_flex()
.elevation_2(cx)
.py(POPOVER_Y_PADDING / 2.)
.children(self.children),
)
.when_some(self.aside, |this, aside| {
this.child(
v_flex()