irongit

fix: full title in preview pane

huncholanehuncholaneauthored
parent f1c8dfecommit 14c32d0a466989b73ab598392f04197a9a4225e6Browse files

1 file changed, +21 -21

+21-21src/views/browser.rs
@@ -417,7 +417,14 @@ impl BrowserView {
417417 PathSegment::Index(i) => format!("[{}]", i),
418418 }
419419 };
420- let selected_label = current_entries.get(self.selection).map(|e| e.label.as_str()).unwrap_or("");
420+ let selected_label = if in_focus_root {
421+ // Use full path for the right pane title in focus mode
422+ self.focused.get(self.selection)
423+ .map(|fp| focus_path_full(fp))
424+ .unwrap_or_default()
425+ } else {
426+ current_entries.get(self.selection).map(|e| e.label.clone()).unwrap_or_default()
427+ };
421428 let focus_suffix = if self.focus_mode && !self.focused.is_empty() {
422429 format!(" ({} focused)", self.focused.len())
423430 } else {
@@ -1229,13 +1236,13 @@ fn focus_path_full(fp: &[PathSegment]) -> String {
12291236 }).collect::<Vec<_>>().join(".")
12301237 }
12311238
1232-/// Short label for a focused path: "filename...lastKey[idx]"
1239+const FOCUS_LABEL_MAX: usize = 40;
1240+
1241+/// Short label for a focused path: "first_word...last_chars" if over max, else full.
12331242 fn focus_path_label(fp: &[PathSegment]) -> String {
1234- if fp.is_empty() {
1235- return String::new();
1236- }
1237- if fp.len() <= 2 {
1238- return focus_path_full(fp);
1243+ let full = focus_path_full(fp);
1244+ if full.len() <= FOCUS_LABEL_MAX {
1245+ return full;
12391246 }
12401247
12411248 let first = match &fp[0] {
@@ -1243,21 +1250,14 @@ fn focus_path_label(fp: &[PathSegment]) -> String {
12431250 PathSegment::Index(i) => format!("[{}]", i),
12441251 };
12451252
1246- // Build the tail: last key + any trailing indices
1247- let mut tail_parts = Vec::new();
1248- for seg in fp.iter().rev() {
1249- match seg {
1250- PathSegment::Index(i) => tail_parts.push(format!("[{}]", i)),
1251- PathSegment::Key(k) => {
1252- tail_parts.push(k.clone());
1253- break;
1254- }
1255- }
1253+ // "first...tail" where tail fills remaining chars
1254+ let ellipsis = "...";
1255+ let budget = FOCUS_LABEL_MAX.saturating_sub(first.len() + ellipsis.len());
1256+ if budget == 0 {
1257+ return format!("{}{}", first, ellipsis);
12561258 }
1257- tail_parts.reverse();
1258- let tail = tail_parts.join(".");
1259-
1260- format!("{}...{}", first, tail)
1259+ let tail = &full[full.len().saturating_sub(budget)..];
1260+ format!("{}{}{}", first, ellipsis, tail)
12611261 }
12621262
12631263 /// Convert an entry label to the correct PathSegment.