summaryrefslogtreecommitdiff
path: root/helix-tui/src/widgets/paragraph.rs
diff options
context:
space:
mode:
authorMo2024-02-27 17:24:05 +0000
committerGitHub2024-02-27 17:24:05 +0000
commit00653c772e7df6f68071d1cb1c92bfe9ca4876f9 (patch)
treeab89132d7fc7d174216264bd367942e9589b2269 /helix-tui/src/widgets/paragraph.rs
parent26b3dc29be886c5a2ed1a5caaaf09eb730829c3e (diff)
Avoid cloning the whole paragraph content just for rendering (#9739)
* Avoid cloning the whole paragraph content just for rendering * Fix tests
Diffstat (limited to 'helix-tui/src/widgets/paragraph.rs')
-rw-r--r--helix-tui/src/widgets/paragraph.rs19
1 files changed, 8 insertions, 11 deletions
diff --git a/helix-tui/src/widgets/paragraph.rs b/helix-tui/src/widgets/paragraph.rs
index 4e839162..9c8ae127 100644
--- a/helix-tui/src/widgets/paragraph.rs
+++ b/helix-tui/src/widgets/paragraph.rs
@@ -28,15 +28,15 @@ fn get_line_offset(line_width: u16, text_area_width: u16, alignment: Alignment)
/// # use helix_tui::widgets::{Block, Borders, Paragraph, Wrap};
/// # use helix_tui::layout::{Alignment};
/// # use helix_view::graphics::{Style, Color, Modifier};
-/// let text = vec![
+/// let text = Text::from(vec![
/// Spans::from(vec![
/// Span::raw("First"),
/// Span::styled("line",Style::default().add_modifier(Modifier::ITALIC)),
/// Span::raw("."),
/// ]),
/// Spans::from(Span::styled("Second line", Style::default().fg(Color::Red))),
-/// ];
-/// Paragraph::new(text)
+/// ]);
+/// Paragraph::new(&text)
/// .block(Block::default().title("Paragraph").borders(Borders::ALL))
/// .style(Style::default().fg(Color::White).bg(Color::Black))
/// .alignment(Alignment::Center)
@@ -51,7 +51,7 @@ pub struct Paragraph<'a> {
/// How to wrap the text
wrap: Option<Wrap>,
/// The text to display
- text: Text<'a>,
+ text: &'a Text<'a>,
/// Scroll
scroll: (u16, u16),
/// Alignment of the text
@@ -70,7 +70,7 @@ pub struct Paragraph<'a> {
/// - Here is another point that is long enough to wrap"#);
///
/// // With leading spaces trimmed (window width of 30 chars):
-/// Paragraph::new(bullet_points.clone()).wrap(Wrap { trim: true });
+/// Paragraph::new(&bullet_points).wrap(Wrap { trim: true });
/// // Some indented points:
/// // - First thing goes here and is
/// // long so that it wraps
@@ -78,7 +78,7 @@ pub struct Paragraph<'a> {
/// // is long enough to wrap
///
/// // But without trimming, indentation is preserved:
-/// Paragraph::new(bullet_points).wrap(Wrap { trim: false });
+/// Paragraph::new(&bullet_points).wrap(Wrap { trim: false });
/// // Some indented points:
/// // - First thing goes here
/// // and is long so that it wraps
@@ -92,15 +92,12 @@ pub struct Wrap {
}
impl<'a> Paragraph<'a> {
- pub fn new<T>(text: T) -> Paragraph<'a>
- where
- T: Into<Text<'a>>,
- {
+ pub fn new(text: &'a Text) -> Paragraph<'a> {
Paragraph {
block: None,
style: Default::default(),
wrap: None,
- text: text.into(),
+ text,
scroll: (0, 0),
alignment: Alignment::Left,
}