tenseleyflow/fackr / 88396f7

Browse files

Fix opening directories as workspaces

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
88396f7c093e11449a65c44ef68736bf27822326
Parents
272e86a
Tree
6c080e2

2 changed files

StatusFile+-
M src/editor/state.rs 7 0
M src/workspace/state.rs 7 2
src/editor/state.rsmodified
@@ -626,6 +626,13 @@ impl Editor {
626626
 
627627
     pub fn open(&mut self, path: &str) -> Result<()> {
628628
         let file_path = PathBuf::from(path);
629
+        let abs_path = file_path.canonicalize().unwrap_or_else(|_| file_path.clone());
630
+
631
+        // If path is a directory, use it as the workspace root
632
+        if abs_path.is_dir() {
633
+            self.workspace = Workspace::open(abs_path)?;
634
+            return Ok(());
635
+        }
629636
 
630637
         // If this is the initial open (empty default tab), use workspace detection
631638
         let is_initial = self.workspace.tabs.len() == 1
src/workspace/state.rsmodified
@@ -752,6 +752,11 @@ impl Workspace {
752752
         let abs_path = file_path.canonicalize()
753753
             .unwrap_or_else(|_| file_path.to_path_buf());
754754
 
755
+        // If path is a directory, use it as the workspace root directly
756
+        if abs_path.is_dir() {
757
+            return Self::open(abs_path);
758
+        }
759
+
755760
         // Determine workspace root
756761
         let root = Self::detect_from_file(&abs_path)
757762
             .or_else(|| abs_path.parent().map(|p| p.to_path_buf()))
@@ -804,8 +809,8 @@ impl Workspace {
804809
                         self.root.join(path)
805810
                     };
806811
 
807
-                    // Only restore if file still exists
808
-                    if full_path.exists() {
812
+                    // Only restore if file still exists and is not a directory
813
+                    if full_path.exists() && !full_path.is_dir() {
809814
                         match BufferEntry::from_file(&full_path, &self.root) {
810815
                             Ok(entry) => {
811816
                                 valid_buffer_map.push(Some(buffers.len()));