Skip to content

Commit

Permalink
🐛 Fixed title incorrectly updating
Browse files Browse the repository at this point in the history
  • Loading branch information
nwrenger committed Apr 6, 2024
1 parent a65b928 commit 95ba033
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ pub fn save(siv: &mut Cursive, other: Option<(&PathBuf, &String)>) -> Result<()>
fs::write(data.0.clone(), data.1)?;
}

update_title(siv, &state, data.0);
update_title(siv, None, data.0);

state.files_edited.remove(data.0);

Expand Down
26 changes: 15 additions & 11 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,27 @@ pub fn open_file(siv: &mut Cursive, file_to_open: &Path) -> Result<()> {
}

// check if file has been added && update title accordingly
update_title(siv, &state, &file_to_open);
update_title(siv, Some(&state), &file_to_open);

Ok(())
}

/// Update the title of the editor panel including the current editing state via adding `*`
pub fn update_title(siv: &mut Cursive, state: &State, path: &Path) {
let title = if state.is_current_file_edited() {
format!(
"{} *",
path.file_name().unwrap_or_default().to_string_lossy()
)
pub fn update_title(siv: &mut Cursive, state: Option<&State>, path: &Path) {
let file_name = path
.file_name()
.unwrap_or_default()
.to_string_lossy()
.to_string();

let title = if let Some(state) = state {
if state.is_current_file_edited() {
file_name + " *"
} else {
file_name
}
} else {
path.file_name()
.unwrap_or_default()
.to_string_lossy()
.to_string()
file_name
};

siv.call_on_name("editor_title", |view: &mut EditorPanel| {
Expand Down

0 comments on commit 95ba033

Please sign in to comment.