move to tab if file already open

This commit is contained in:
Penwing 2024-01-26 20:53:16 +01:00
parent 94ef5675b7
commit fa2104b9de
2 changed files with 195 additions and 189 deletions

View file

@ -172,6 +172,14 @@ impl Calcifer {
} }
pub fn open_file(&mut self, path_option: Option<&Path>) { pub fn open_file(&mut self, path_option: Option<&Path>) {
if let Some(path) = path_option.clone() {
for (index, tab) in self.tabs.clone().iter().enumerate() {
if tab.path == path {
self.selected_tab = tools::TabNumber::from_index(index);
return
}
}
}
if self.tabs.len() < MAX_TABS { if self.tabs.len() < MAX_TABS {
if let Some(path) = path_option { if let Some(path) = path_option {
self.tabs.push(tools::Tab::new(path.to_path_buf())); self.tabs.push(tools::Tab::new(path.to_path_buf()));

View file

@ -57,8 +57,6 @@ impl Tab {
.and_then(|ext| ext.to_str()) .and_then(|ext| ext.to_str())
.unwrap_or_default(); .unwrap_or_default();
println!("language : {}", extension);
Self { Self {
path: file_path.clone(), path: file_path.clone(),
code: text, code: text,