Fix opening directories as workspaces
Authored by
mfwolffe <wolffemf@dukes.jmu.edu>
- SHA
88396f7c093e11449a65c44ef68736bf27822326- Parents
-
272e86a - Tree
6c080e2
88396f7
88396f7c093e11449a65c44ef68736bf27822326272e86a
6c080e2| Status | File | + | - |
|---|---|---|---|
| M |
src/editor/state.rs
|
7 | 0 |
| M |
src/workspace/state.rs
|
7 | 2 |
src/editor/state.rsmodified@@ -626,6 +626,13 @@ impl Editor { | ||
| 626 | 626 | |
| 627 | 627 | pub fn open(&mut self, path: &str) -> Result<()> { |
| 628 | 628 | 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 | + } | |
| 629 | 636 | |
| 630 | 637 | // If this is the initial open (empty default tab), use workspace detection |
| 631 | 638 | let is_initial = self.workspace.tabs.len() == 1 |
src/workspace/state.rsmodified@@ -752,6 +752,11 @@ impl Workspace { | ||
| 752 | 752 | let abs_path = file_path.canonicalize() |
| 753 | 753 | .unwrap_or_else(|_| file_path.to_path_buf()); |
| 754 | 754 | |
| 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 | + | |
| 755 | 760 | // Determine workspace root |
| 756 | 761 | let root = Self::detect_from_file(&abs_path) |
| 757 | 762 | .or_else(|| abs_path.parent().map(|p| p.to_path_buf())) |
@@ -804,8 +809,8 @@ impl Workspace { | ||
| 804 | 809 | self.root.join(path) |
| 805 | 810 | }; |
| 806 | 811 | |
| 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() { | |
| 809 | 814 | match BufferEntry::from_file(&full_path, &self.root) { |
| 810 | 815 | Ok(entry) => { |
| 811 | 816 | valid_buffer_map.push(Some(buffers.len())); |