Skip to content

Commit c7b5c1a

Browse files
committed
chore: revert new on Scrollable
but due to limitation of rustc rust-lang/rust#20400 we can't have two new functions based on non-overlapping associated types
1 parent d1a9437 commit c7b5c1a

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/bin/ui/scrollable/markdown/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::Scrollable;
2+
use crate::Result;
23
use ratatui::layout::Rect;
34
use std::{fmt, ops::Deref};
45
use term_rustdoc::tree::Text as StyledText;
@@ -44,3 +45,14 @@ impl StyledLines {
4445
parse::md(doc)
4546
}
4647
}
48+
49+
impl ScrollText {
50+
pub fn new_text(doc: &str, area: Rect) -> Result<Self> {
51+
// TODO:max_windth and text wrap for markdown
52+
Ok(Scrollable {
53+
lines: StyledLines::new(doc),
54+
area,
55+
..Default::default()
56+
})
57+
}
58+
}

src/bin/ui/scrollable/mod.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,22 @@ impl<Lines: Default> Default for Scrollable<Lines> {
6060
}
6161
}
6262

63-
impl<Lines: Deref<Target = [TreeLine]>> Scrollable<Lines> {
64-
pub fn new(lines: Lines, full: Rect) -> Result<Self> {
63+
impl<Lines: Default + Deref<Target = [TreeLine]>> Scrollable<Lines> {
64+
pub fn new(lines: Lines, area: Rect) -> Result<Self> {
6565
let w = lines.as_ref().iter().map(TreeLine::width).max();
6666
let max_windth = w.ok_or_else(|| err!("The documentation is empty with no items."))?;
67-
if full.width < max_windth {
67+
if area.width < max_windth {
6868
warn!(
69-
full.width,
69+
area.width,
7070
max_windth, "Outline width exceeds the area width, so lines may be truncated."
7171
);
7272
}
7373

74-
let (start, cursor, select) = Default::default();
7574
Ok(Self {
7675
lines,
7776
max_windth,
78-
area: full,
79-
start,
80-
cursor,
81-
select,
77+
area,
78+
..Default::default()
8279
})
8380
}
8481
}

0 commit comments

Comments
 (0)