@@ -1,10 +1,10 @@
use std::{iter, mem, ops::Range};
use crate::{
- black, phi, point, quad, rems, AbsoluteLength, BorrowWindow, Bounds, ContentMask, Corners,
- CornersRefinement, CursorStyle, DefiniteLength, Edges, EdgesRefinement, Font, FontFeatures,
- FontStyle, FontWeight, Hsla, Length, Pixels, Point, PointRefinement, Rgba, SharedString, Size,
- SizeRefinement, Styled, TextRun, WindowContext,
+ black, phi, point, quad, rems, AbsoluteLength, BorrowAppContext, BorrowWindow, Bounds,
+ ContentMask, Corners, CornersRefinement, CursorStyle, DefiniteLength, Edges, EdgesRefinement,
+ Font, FontFeatures, FontStyle, FontWeight, Hsla, Length, Pixels, Point, PointRefinement, Rgba,
+ SharedString, Size, SizeRefinement, Styled, TextRun, WindowContext,
};
use collections::HashSet;
use refineable::{Cascade, Refineable};
@@ -308,54 +308,54 @@ impl Style {
}
}
- // pub fn apply_text_style<C, F, R>(&self, cx: &mut C, f: F) -> R
- // where
- // C: BorrowAppContext,
- // F: FnOnce(&mut C) -> R,
- // {
- // if self.text.is_some() {
- // cx.with_text_style(Some(self.text.clone()), f)
- // } else {
- // f(cx)
- // }
- // }
-
- // /// Apply overflow to content mask
- // pub fn apply_overflow<C, F, R>(&self, bounds: Bounds<Pixels>, cx: &mut C, f: F) -> R
- // where
- // C: BorrowWindow,
- // F: FnOnce(&mut C) -> R,
- // {
- // let current_mask = cx.content_mask();
-
- // let min = current_mask.bounds.origin;
- // let max = current_mask.bounds.lower_right();
-
- // let mask_bounds = match (
- // self.overflow.x == Overflow::Visible,
- // self.overflow.y == Overflow::Visible,
- // ) {
- // // x and y both visible
- // (true, true) => return f(cx),
- // // x visible, y hidden
- // (true, false) => Bounds::from_corners(
- // point(min.x, bounds.origin.y),
- // point(max.x, bounds.lower_right().y),
- // ),
- // // x hidden, y visible
- // (false, true) => Bounds::from_corners(
- // point(bounds.origin.x, min.y),
- // point(bounds.lower_right().x, max.y),
- // ),
- // // both hidden
- // (false, false) => bounds,
- // };
- // let mask = ContentMask {
- // bounds: mask_bounds,
- // };
-
- // cx.with_content_mask(Some(mask), f)
- // }
+ pub fn apply_text_style<C, F, R>(&self, cx: &mut C, f: F) -> R
+ where
+ C: BorrowAppContext,
+ F: FnOnce(&mut C) -> R,
+ {
+ if self.text.is_some() {
+ cx.with_text_style(Some(self.text.clone()), f)
+ } else {
+ f(cx)
+ }
+ }
+
+ /// Apply overflow to content mask
+ pub fn apply_overflow<C, F, R>(&self, bounds: Bounds<Pixels>, cx: &mut C, f: F) -> R
+ where
+ C: BorrowWindow,
+ F: FnOnce(&mut C) -> R,
+ {
+ let current_mask = cx.content_mask();
+
+ let min = current_mask.bounds.origin;
+ let max = current_mask.bounds.lower_right();
+
+ let mask_bounds = match (
+ self.overflow.x == Overflow::Visible,
+ self.overflow.y == Overflow::Visible,
+ ) {
+ // x and y both visible
+ (true, true) => return f(cx),
+ // x visible, y hidden
+ (true, false) => Bounds::from_corners(
+ point(min.x, bounds.origin.y),
+ point(max.x, bounds.lower_right().y),
+ ),
+ // x hidden, y visible
+ (false, true) => Bounds::from_corners(
+ point(bounds.origin.x, min.y),
+ point(bounds.lower_right().x, max.y),
+ ),
+ // both hidden
+ (false, false) => bounds,
+ };
+ let mask = ContentMask {
+ bounds: mask_bounds,
+ };
+
+ cx.with_content_mask(Some(mask), f)
+ }
/// Paints the background of an element styled with this style.
pub fn paint(
@@ -1,3 +1,4 @@
+use anyhow::bail;
use futures::FutureExt;
use gpui::{
AnyElement, ElementId, FontStyle, FontWeight, HighlightStyle, InteractiveText, IntoElement,
@@ -85,31 +86,6 @@ impl RichText {
})
.into_any_element()
}
-
- // pub fn add_mention(
- // &mut self,
- // range: Range<usize>,
- // is_current_user: bool,
- // mention_style: HighlightStyle,
- // ) -> anyhow::Result<()> {
- // if range.end > self.text.len() {
- // bail!(
- // "Mention in range {range:?} is outside of bounds for a message of length {}",
- // self.text.len()
- // );
- // }
-
- // if is_current_user {
- // self.region_ranges.push(range.clone());
- // self.regions.push(RenderedRegion {
- // background_kind: Some(BackgroundKind::Mention),
- // link_url: None,
- // });
- // }
- // self.highlights
- // .push((range, Highlight::Highlight(mention_style)));
- // Ok(())
- // }
}
pub fn render_markdown_mut(
@@ -272,13 +248,6 @@ pub fn render_markdown(
language_registry: &Arc<LanguageRegistry>,
language: Option<&Arc<Language>>,
) -> RichText {
- // let mut data = RichText {
- // text: Default::default(),
- // highlights: Default::default(),
- // region_ranges: Default::default(),
- // regions: Default::default(),
- // };
-
let mut text = String::new();
let mut highlights = Vec::new();
let mut link_ranges = Vec::new();