From 22ec51b7e7512070a2af3b9cd2951f34909209a4 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 15 Feb 2024 15:40:59 -0700 Subject: [PATCH] Truncate recent items, fix open recent project issues --- src/main.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index ec2827d..d7154a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -474,12 +474,20 @@ impl App { *open = true; *root = true; + for (project_name, project_path) in self.projects.iter() { + if project_path == path { + // Project already open + return; + } + } + // Save the absolute path self.projects.push((name.to_string(), path.to_path_buf())); // Add to recent projects, ensuring only one entry self.config.recent_projects.retain(|x| x != path); self.config.recent_projects.push_front(path.to_path_buf()); + self.config.recent_projects.truncate(10); self.save_config_no_update(); } _ => { @@ -537,6 +545,7 @@ impl App { // Add to recent files, ensuring only one entry self.config.recent_files.retain(|x| x != &canonical); self.config.recent_files.push_front(canonical.to_path_buf()); + self.config.recent_files.truncate(10); self.save_config_no_update(); let mut tab = EditorTab::new(&self.config); @@ -1623,7 +1632,7 @@ impl Application for App { } } Message::OpenRecentProject(index) => { - if let Some(path) = self.config.recent_files.get(index).cloned() { + if let Some(path) = self.config.recent_projects.get(index).cloned() { self.open_project(path); } }