fix bufferline overflow

pull/8018/head
Nawaf 1 year ago
parent 01a1e5ec2a
commit 1459a9cdcd

@ -539,31 +539,58 @@ impl EditorView {
let mut x = viewport.x; let mut x = viewport.x;
let current_doc = view!(editor).doc; let current_doc = view!(editor).doc;
let mut current_doc_idx = None;
let width = viewport.right();
let mut needed_width = 0;
let entries: Vec<String> = editor
.documents()
.enumerate()
.map(|(idx, doc)| {
let fname = doc
.path()
.unwrap_or(&scratch)
.file_name()
.unwrap_or_default()
.to_str()
.unwrap_or_default();
let text = format!(" {}{} ", fname, if doc.is_modified() { "[+]" } else { "" });
if doc.id() == current_doc {
current_doc_idx = Some(idx);
needed_width += text.len();
} else if current_doc_idx.is_none() {
needed_width += text.len();
}
text
})
.collect();
for doc in editor.documents() { let mut to_trim = needed_width.saturating_sub(width as usize);
let fname = doc for (idx, filename) in entries.iter().enumerate() {
.path() let mut text = filename.as_str();
.unwrap_or(&scratch) if to_trim > 0 {
.file_name() if text.len() > to_trim {
.unwrap_or_default() text = &filename[to_trim..];
.to_str() to_trim = 0;
.unwrap_or_default(); } else if to_trim > text.len() {
to_trim -= text.len();
let style = if current_doc == doc.id() { continue;
}
}
let style = if idx == current_doc_idx.unwrap() {
bufferline_active bufferline_active
} else { } else {
bufferline_inactive bufferline_inactive
}; };
let text = format!(" {}{} ", fname, if doc.is_modified() { "[+]" } else { "" }); let rem_width = width.saturating_sub(x);
let used_width = viewport.x.saturating_sub(x);
let rem_width = surface.area.width.saturating_sub(used_width);
x = surface x = surface
.set_stringn(x, viewport.y, text, rem_width as usize, style) .set_stringn(x, viewport.y, text, rem_width as usize, style)
.0; .0;
if x >= surface.area.right() { if x >= width {
break; break;
} }
} }

Loading…
Cancel
Save