Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions src/screen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,27 +399,8 @@ pub(crate) fn layout_screen<'a>(layout: &mut UiTree<'a>, size: Size, screen: &'a

let span_width = span.content.graphemes(true).count();

if line_end + span_width >= size.width as usize {
// Truncate the span and insert an ellipsis to indicate overflow
let overflow = line_end + span_width - size.width as usize;
line_end = size.width as usize;
ui::layout_span(
layout,
(
span.content
.graphemes(true)
.take(span_width.saturating_sub(overflow + 1))
.collect::<String>()
.into(),
style,
),
);
layout_span(layout, ("…".into(), bg));
} else {
// Insert the span as normal
line_end += span_width;
ui::layout_span(layout, (span.content, style));
}
line_end += span_width;
ui::layout_span(layout, (span.content, style));
});

// Add ellipsis indicator for collapsed sections
Expand Down
20 changes: 18 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,24 @@ pub(crate) fn layout_line<'a>(layout: &mut UiTree<'a>, line: Line<'a>) {
}

pub(crate) fn layout_span<'a>(layout: &mut UiTree<'a>, span: (Cow<'a, str>, Style)) {
let width = span.0.graphemes(true).count() as u16;
layout.leaf_with_size(span, [width, 1]);
match span.0 {
Cow::Borrowed(s) => {
for word in s.split_word_bounds() {
layout.leaf_with_size(
(Cow::Borrowed(word), span.1),
[word.graphemes(true).count() as u16, 1],
);
}
}
Cow::Owned(s) => {
for word in s.split_word_bounds() {
layout.leaf_with_size(
(Cow::Owned(word.into()), span.1),
[word.graphemes(true).count() as u16, 1],
);
}
}
}
}

pub(crate) fn repeat_chars(layout: &mut UiTree, count: usize, chars: &'static str, style: Style) {
Expand Down
16 changes: 6 additions & 10 deletions src/ui/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,13 @@ impl<T: std::fmt::Debug + Clone> LayoutTree<T> {
child_data.pos = Some(start + cursor);
} else {
// Child doesn't fit where cursor currently is
// TODO Uncomment to include wrapping (tests below)
// // Try wrapping to next line/column first
// let next_line = size * dir.axis().flip();
let next_line = size * dir.axis().flip();

// if (next_line + child_data.size).fits(avail_size) {
// // Fits completely on next line
// cursor = next_line;
// child_data.pos = Some(start + cursor);
// } else

if (cursor + Vec2(1, 1)).fits(avail_size) {
if (next_line + child_data.size).fits(avail_size) {
// Fits completely on next line
cursor = next_line;
child_data.pos = Some(start + cursor);
} else if (cursor + Vec2(1, 1)).fits(avail_size) {
// Can't wrap, but we can fit at least one cell where the cursor currently is
child_data.pos = Some(start + cursor);
child_data.size = child_data.size.min(avail_size.saturating_sub(cursor));
Expand Down
Loading