on master help sign in
Truncate the start of file paths in the StatusLine (#1351)

* Truncate the start of file paths in the StatusLine * cargo fmt Co-authored-by: Bódi Balázs <97936@4ig.hu>

commit60f3225c7f3375b546e8ec9032739d073a7c363c authorBB <bodidev@gmail.com> dateSat 25 Dec 2021, 05:24 (5 years ago) parent8aa0b8e
1 file changed+25−15
helix-term/src/ui/editor.rs+25−15
helix-term/src/ui/editor.rs+25−15
@@ -548,21 +548,6 @@ impl EditorView {
548548 }
549549 surface.set_string(viewport.x + 5, viewport.y, progress, base_style);
550550
551− let rel_path = doc.relative_path();
552− let path = rel_path
553− .as_ref()
554− .map(|p| p.to_string_lossy())
555− .unwrap_or_else(|| SCRATCH_BUFFER_NAME.into());
556−
557− let title = format!("{}{}", path, if doc.is_modified() { "[+]" } else { "" });
558− surface.set_stringn(
559− viewport.x + 8,
560− viewport.y,
561− title,
562− viewport.width.saturating_sub(6) as usize,
563− base_style,
564− );
565−
566551 //-------------------------------
567552 // Right side of the status line.
568553 //-------------------------------
@@ -646,6 +631,31 @@ impl EditorView {
646631 &right_side_text,
647632 right_side_text.width() as u16,
648633 );
634+
635+ //-------------------------------
636+ // Middle / File path / Title
637+ //-------------------------------
638+ let title = {
639+ let rel_path = doc.relative_path();
640+ let path = rel_path
641+ .as_ref()
642+ .map(|p| p.to_string_lossy())
643+ .unwrap_or_else(|| SCRATCH_BUFFER_NAME.into());
644+ format!("{}{}", path, if doc.is_modified() { "[+]" } else { "" })
645+ };
646+
647+ surface.set_string_truncated(
648+ viewport.x + 8, // 8: 1 space + 3 char mode string + 1 space + 1 spinner + 1 space
649+ viewport.y,
650+ title,
651+ viewport
652+ .width
653+ .saturating_sub(6)
654+ .saturating_sub(right_side_text.width() as u16 + 1) as usize, // "+ 1": a space between the title and the selection info
655+ base_style,
656+ true,
657+ true,
658+ );
649659 }
650660
651661 /// Handle events by looking them up in `self.keymaps`. Returns None