Skip to content

Commit

Permalink
feat: improve tab title for mod.rs files
Browse files Browse the repository at this point in the history
  • Loading branch information
mmstick authored and jackpot51 committed Jan 17, 2024
1 parent ed56f3d commit 0581f96
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ impl EditorTab {
if let Some(path) = &self.path_opt {
match path.file_name() {
Some(file_name_os) => match file_name_os.to_str() {
Some(file_name) => file_name.to_string(),
Some(file_name) => match file_name {
"mod.rs" => title_with_parent(&path, file_name),
_ => file_name.to_string(),
},
None => format!("{}", path.display()),
},
None => format!("{}", path.display()),
Expand Down Expand Up @@ -290,3 +293,18 @@ impl EditorTab {
false
}
}

/// Includes parent name in tab title
///
/// Useful for distinguishing between Rust modules named `mod.rs`
fn title_with_parent(path: &std::path::Path, file_name: &str) -> String {
let parent_name = path
.parent()
.and_then(|path| path.file_name())
.and_then(|os_str| os_str.to_str());

match parent_name {
Some(parent) => [parent, "/", file_name].concat(),
None => file_name.to_string(),
}
}

0 comments on commit 0581f96

Please sign in to comment.