editor: Fix completion width align to longest item. (#1281)
This commit is contained in:
parent
bf5650b5db
commit
bd3bffaf67
6 changed files with 19 additions and 34 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"label": "as",
|
"label": "as",
|
||||||
|
"detail": "as TYPE",
|
||||||
"documentation": "Perform a safe type cast.\n\n## Example:\n```rust\nlet x: u32 = 42;\nlet y: u64 = x as u64;\n```"
|
"documentation": "Perform a safe type cast.\n\n## Example:\n```rust\nlet x: u32 = 42;\nlet y: u64 = x as u64;\n```"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -9,6 +10,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "const",
|
"label": "const",
|
||||||
|
"detail": "const NAME: Type = ..;",
|
||||||
"documentation": "Define a constant value.\n\n**Note:** Constants are immutable and must have their type explicitly declared."
|
"documentation": "Define a constant value.\n\n**Note:** Constants are immutable and must have their type explicitly declared."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ const MAX_MENU_HEIGHT: Pixels = px(480.);
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
actions, h_flex,
|
actions, h_flex,
|
||||||
input::{self, InputState},
|
input::{self, popovers::editor_popover, InputState},
|
||||||
list::{List, ListDelegate, ListEvent},
|
list::{List, ListDelegate, ListEvent},
|
||||||
ActiveTheme, IndexPath, Selectable,
|
ActiveTheme, IndexPath, Selectable,
|
||||||
};
|
};
|
||||||
|
|
@ -330,21 +330,9 @@ impl Render for CodeActionMenu {
|
||||||
let max_width = MAX_MENU_WIDTH.min(window.bounds().size.width - pos.x);
|
let max_width = MAX_MENU_WIDTH.min(window.bounds().size.width - pos.x);
|
||||||
|
|
||||||
deferred(
|
deferred(
|
||||||
div()
|
editor_popover("code-action-menu", cx)
|
||||||
.id("code-action-menu")
|
|
||||||
.absolute()
|
|
||||||
.left(pos.x)
|
.left(pos.x)
|
||||||
.top(pos.y)
|
.top(pos.y)
|
||||||
.flex_none()
|
|
||||||
.occlude()
|
|
||||||
.p_1()
|
|
||||||
.text_xs()
|
|
||||||
.text_color(cx.theme().popover_foreground)
|
|
||||||
.bg(cx.theme().popover)
|
|
||||||
.border_1()
|
|
||||||
.border_color(cx.theme().border)
|
|
||||||
.rounded(cx.theme().radius)
|
|
||||||
.shadow_md()
|
|
||||||
.max_w(max_width)
|
.max_w(max_width)
|
||||||
.min_w(px(120.))
|
.min_w(px(120.))
|
||||||
.child(self.list.clone())
|
.child(self.list.clone())
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ use crate::{
|
||||||
actions, h_flex,
|
actions, h_flex,
|
||||||
input::{
|
input::{
|
||||||
self,
|
self,
|
||||||
popovers::{popover, render_markdown},
|
popovers::{editor_popover, render_markdown},
|
||||||
InputState, RopeExt,
|
InputState, RopeExt,
|
||||||
},
|
},
|
||||||
label::Label,
|
label::Label,
|
||||||
|
|
@ -360,7 +360,9 @@ impl CompletionMenu {
|
||||||
let longest_ix = items
|
let longest_ix = items
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.max_by_key(|(_, item)| item.label.len())
|
.max_by_key(|(_, item)| {
|
||||||
|
item.label.len() + item.detail.as_ref().map(|d| d.len()).unwrap_or(0)
|
||||||
|
})
|
||||||
.map(|(ix, _)| ix)
|
.map(|(ix, _)| ix)
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
|
||||||
|
|
@ -432,7 +434,7 @@ impl Render for CompletionMenu {
|
||||||
.items_start()
|
.items_start()
|
||||||
.when(vertical_layout, |this| this.flex_col())
|
.when(vertical_layout, |this| this.flex_col())
|
||||||
.child(
|
.child(
|
||||||
popover("completion-menu", cx)
|
editor_popover("completion-menu", cx)
|
||||||
.max_w(max_width)
|
.max_w(max_width)
|
||||||
.min_w(px(120.))
|
.min_w(px(120.))
|
||||||
.child(self.list.clone())
|
.child(self.list.clone())
|
||||||
|
|
@ -456,7 +458,7 @@ impl Render for CompletionMenu {
|
||||||
|
|
||||||
this.child(
|
this.child(
|
||||||
div().child(
|
div().child(
|
||||||
popover("completion-menu", cx)
|
editor_popover("completion-menu", cx)
|
||||||
.w(MAX_MENU_WIDTH)
|
.w(MAX_MENU_WIDTH)
|
||||||
.px_2()
|
.px_2()
|
||||||
.child(render_markdown("doc", doc, window, cx)),
|
.child(render_markdown("doc", doc, window, cx)),
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use gpui::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
input::{popovers::render_markdown, InputState},
|
input::{popovers::render_markdown, InputState},
|
||||||
ActiveTheme as _, StyledExt,
|
StyledExt,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct HoverPopover {
|
pub struct HoverPopover {
|
||||||
|
|
@ -194,11 +194,7 @@ impl Element for Popover {
|
||||||
.occlude()
|
.occlude()
|
||||||
.p_1()
|
.p_1()
|
||||||
.text_xs()
|
.text_xs()
|
||||||
.text_color(cx.theme().popover_foreground)
|
.popover_style(cx)
|
||||||
.bg(cx.theme().popover)
|
|
||||||
.border_1()
|
|
||||||
.border_color(cx.theme().border)
|
|
||||||
.rounded(cx.theme().radius)
|
|
||||||
.shadow_md()
|
.shadow_md()
|
||||||
.max_w(max_width)
|
.max_w(max_width)
|
||||||
.refine_style(&self.style)
|
.refine_style(&self.style)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ use gpui::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
text::{TextView, TextViewStyle},
|
text::{TextView, TextViewStyle},
|
||||||
ActiveTheme as _,
|
StyledExt as _,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) enum ContextMenu {
|
pub(crate) enum ContextMenu {
|
||||||
|
|
@ -63,17 +63,13 @@ pub(super) fn render_markdown(
|
||||||
.selectable()
|
.selectable()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn popover(id: impl Into<ElementId>, cx: &App) -> Stateful<Div> {
|
pub(super) fn editor_popover(id: impl Into<ElementId>, cx: &App) -> Stateful<Div> {
|
||||||
div()
|
div()
|
||||||
.id(id)
|
.id(id)
|
||||||
.flex_none()
|
.flex_none()
|
||||||
.occlude()
|
.occlude()
|
||||||
.p_1()
|
.popover_style(cx)
|
||||||
.text_xs()
|
|
||||||
.text_color(cx.theme().popover_foreground)
|
|
||||||
.bg(cx.theme().popover)
|
|
||||||
.border_1()
|
|
||||||
.border_color(cx.theme().border)
|
|
||||||
.rounded(cx.theme().radius)
|
|
||||||
.shadow_md()
|
.shadow_md()
|
||||||
|
.text_xs()
|
||||||
|
.p_1()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -190,8 +190,9 @@ pub trait StyledExt: Styled + Sized {
|
||||||
|
|
||||||
/// Set as Popover style
|
/// Set as Popover style
|
||||||
#[inline]
|
#[inline]
|
||||||
fn popover_style(self, cx: &mut App) -> Self {
|
fn popover_style(self, cx: &App) -> Self {
|
||||||
self.bg(cx.theme().popover)
|
self.bg(cx.theme().popover)
|
||||||
|
.text_color(cx.theme().popover_foreground)
|
||||||
.border_1()
|
.border_1()
|
||||||
.border_color(cx.theme().border)
|
.border_color(cx.theme().border)
|
||||||
.shadow_lg()
|
.shadow_lg()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue