Don't perform wrapping in completions

This commit is contained in:
Antonio Scandurra 2023-11-22 14:23:09 +01:00
parent fff2d7955e
commit 2b6e8de11f
4 changed files with 43 additions and 8 deletions

View file

@ -44,7 +44,7 @@ use gpui::{
EventEmitter, FocusHandle, FocusableView, FontFeatures, FontStyle, FontWeight, HighlightStyle, EventEmitter, FocusHandle, FocusableView, FontFeatures, FontStyle, FontWeight, HighlightStyle,
Hsla, InputHandler, KeyContext, Model, MouseButton, ParentElement, Pixels, Render, Hsla, InputHandler, KeyContext, Model, MouseButton, ParentElement, Pixels, Render,
SharedString, Styled, Subscription, Task, TextStyle, UniformListScrollHandle, View, SharedString, Styled, Subscription, Task, TextStyle, UniformListScrollHandle, View,
ViewContext, VisualContext, WeakView, WindowContext, ViewContext, VisualContext, WeakView, WhiteSpace, WindowContext,
}; };
use highlight_matching_bracket::refresh_matching_bracket_highlights; use highlight_matching_bracket::refresh_matching_bracket_highlights;
use hover_popover::{hide_hover, HoverState}; use hover_popover::{hide_hover, HoverState};
@ -1358,9 +1358,11 @@ impl CompletionsMenu {
// //
div() div()
.id(mat.candidate_id) .id(mat.candidate_id)
.whitespace_nowrap()
.overflow_hidden()
.bg(gpui::green()) .bg(gpui::green())
.hover(|style| style.bg(gpui::blue())) .hover(|style| style.bg(gpui::blue()))
.when(item_ix == selected_item, |div| div.bg(gpui::blue())) .when(item_ix == selected_item, |div| div.bg(gpui::red()))
.child(SharedString::from(completion.label.text.clone())) .child(SharedString::from(completion.label.text.clone()))
.min_w(px(300.)) .min_w(px(300.))
.max_w(px(700.)) .max_w(px(700.))
@ -9396,6 +9398,7 @@ impl Render for Editor {
font_style: FontStyle::Normal, font_style: FontStyle::Normal,
line_height: relative(1.).into(), line_height: relative(1.).into(),
underline: None, underline: None,
white_space: WhiteSpace::Normal,
}, },
EditorMode::AutoHeight { max_lines } => todo!(), EditorMode::AutoHeight { max_lines } => todo!(),
@ -9409,6 +9412,7 @@ impl Render for Editor {
font_style: FontStyle::Normal, font_style: FontStyle::Normal,
line_height: relative(settings.buffer_line_height.value()), line_height: relative(settings.buffer_line_height.value()),
underline: None, underline: None,
white_space: WhiteSpace::Normal,
}, },
}; };

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
Bounds, Element, ElementId, LayoutId, Pixels, RenderOnce, SharedString, Size, TextRun, Bounds, Element, ElementId, LayoutId, Pixels, RenderOnce, SharedString, Size, TextRun,
WindowContext, WrappedLine, WhiteSpace, WindowContext, WrappedLine,
}; };
use anyhow::anyhow; use anyhow::anyhow;
use parking_lot::{Mutex, MutexGuard}; use parking_lot::{Mutex, MutexGuard};
@ -159,10 +159,14 @@ impl TextState {
let element_state = self.clone(); let element_state = self.clone();
move |known_dimensions, available_space| { move |known_dimensions, available_space| {
let wrap_width = known_dimensions.width.or(match available_space.width { let wrap_width = if text_style.white_space == WhiteSpace::Normal {
crate::AvailableSpace::Definite(x) => Some(x), known_dimensions.width.or(match available_space.width {
_ => None, crate::AvailableSpace::Definite(x) => Some(x),
}); _ => None,
})
} else {
None
};
if let Some(text_state) = element_state.0.lock().as_ref() { if let Some(text_state) = element_state.0.lock().as_ref() {
if text_state.size.is_some() if text_state.size.is_some()

View file

@ -128,6 +128,13 @@ pub struct BoxShadow {
pub spread_radius: Pixels, pub spread_radius: Pixels,
} }
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub enum WhiteSpace {
#[default]
Normal,
Nowrap,
}
#[derive(Refineable, Clone, Debug)] #[derive(Refineable, Clone, Debug)]
#[refineable(Debug)] #[refineable(Debug)]
pub struct TextStyle { pub struct TextStyle {
@ -139,6 +146,7 @@ pub struct TextStyle {
pub font_weight: FontWeight, pub font_weight: FontWeight,
pub font_style: FontStyle, pub font_style: FontStyle,
pub underline: Option<UnderlineStyle>, pub underline: Option<UnderlineStyle>,
pub white_space: WhiteSpace,
} }
impl Default for TextStyle { impl Default for TextStyle {
@ -152,6 +160,7 @@ impl Default for TextStyle {
font_weight: FontWeight::default(), font_weight: FontWeight::default(),
font_style: FontStyle::default(), font_style: FontStyle::default(),
underline: None, underline: None,
white_space: WhiteSpace::Normal,
} }
} }
} }

View file

@ -1,7 +1,7 @@
use crate::{ use crate::{
self as gpui, hsla, point, px, relative, rems, AbsoluteLength, AlignItems, CursorStyle, self as gpui, hsla, point, px, relative, rems, AbsoluteLength, AlignItems, CursorStyle,
DefiniteLength, Display, Fill, FlexDirection, Hsla, JustifyContent, Length, Position, DefiniteLength, Display, Fill, FlexDirection, Hsla, JustifyContent, Length, Position,
SharedString, StyleRefinement, Visibility, SharedString, StyleRefinement, Visibility, WhiteSpace,
}; };
use crate::{BoxShadow, TextStyleRefinement}; use crate::{BoxShadow, TextStyleRefinement};
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
@ -101,6 +101,24 @@ pub trait Styled: Sized {
self self
} }
/// Sets the whitespace of the element to `normal`.
/// [Docs](https://tailwindcss.com/docs/whitespace#normal)
fn whitespace_normal(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
.white_space = Some(WhiteSpace::Normal);
self
}
/// Sets the whitespace of the element to `nowrap`.
/// [Docs](https://tailwindcss.com/docs/whitespace#nowrap)
fn whitespace_nowrap(mut self) -> Self {
self.text_style()
.get_or_insert_with(Default::default)
.white_space = Some(WhiteSpace::Nowrap);
self
}
/// Sets the flex direction of the element to `column`. /// Sets the flex direction of the element to `column`.
/// [Docs](https://tailwindcss.com/docs/flex-direction#column) /// [Docs](https://tailwindcss.com/docs/flex-direction#column)
fn flex_col(mut self) -> Self { fn flex_col(mut self) -> Self {