aboutsummaryrefslogtreecommitdiff
path: root/helix-tui/src/buffer.rs
diff options
context:
space:
mode:
authormWalrus2023-03-22 14:38:34 +0000
committerBlaž Hrastnik2023-03-31 06:19:17 +0000
commite72be529968071abcd5fce1d9a06e8e2e2bbaacf (patch)
tree8c0f12984f736c8fce0b0241e541073218f318a4 /helix-tui/src/buffer.rs
parenta863fd89e149ae698f1c7d1d493cc4197abd430a (diff)
Truncate paths in the file picker (#6410)
Diffstat (limited to 'helix-tui/src/buffer.rs')
-rw-r--r--helix-tui/src/buffer.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/helix-tui/src/buffer.rs b/helix-tui/src/buffer.rs
index b1fd4478..2c212b12 100644
--- a/helix-tui/src/buffer.rs
+++ b/helix-tui/src/buffer.rs
@@ -433,6 +433,31 @@ impl Buffer {
(x_offset as u16, y)
}
+ pub fn set_spans_truncated(&mut self, x: u16, y: u16, spans: &Spans, width: u16) -> (u16, u16) {
+ let mut remaining_width = width;
+ let mut alt_x = x;
+ let (text, styles) =
+ spans
+ .0
+ .iter()
+ .fold((String::new(), vec![]), |(mut s, mut h), span| {
+ s.push_str(span.content.as_ref());
+ let mut styles = span
+ .styled_graphemes(span.style)
+ .map(|grapheme| grapheme.style)
+ .collect();
+ h.append(&mut styles);
+
+ let w = span.width() as u16;
+ alt_x = alt_x + w;
+ remaining_width = remaining_width.saturating_sub(w);
+
+ (s, h)
+ });
+ self.set_string_truncated(x, y, &text, width.into(), |idx| styles[idx], true, true);
+ (x, y)
+ }
+
pub fn set_spans(&mut self, x: u16, y: u16, spans: &Spans, width: u16) -> (u16, u16) {
let mut remaining_width = width;
let mut x = x;