Release Notes: - N/A
Showing the changes to crates/worktree/src (1 of 9 files). Show all
Unified · Split
| @@ -1172,6 +1172,31 @@ impl Worktree { · 1171 unmodified lines | |||
| 1172 | pub fn is_single_file(&self) -> bool { | 1172 | pub fn is_single_file(&self) -> bool { |
| 1173 | self.root_dir().is_none() | 1173 | self.root_dir().is_none() |
| 1174 | } | 1174 | } |
| 1175 | |||
| 1176 | /// For visible worktrees, returns the path with the worktree name as the first component. | ||
| 1177 | /// Otherwise, returns an absolute path. | ||
| 1178 | pub fn full_path(&self, worktree_relative_path: &Path) -> PathBuf { | ||
| 1179 | let mut full_path = PathBuf::new(); | ||
| 1180 | |||
| 1181 | if self.is_visible() { | ||
| 1182 | full_path.push(self.root_name()); | ||
| 1183 | } else { | ||
| 1184 | let path = self.abs_path(); | ||
| 1185 | |||
| 1186 | if self.is_local() && path.starts_with(home_dir().as_path()) { | ||
| 1187 | full_path.push("~"); | ||
| 1188 | full_path.push(path.strip_prefix(home_dir().as_path()).unwrap()); | ||
| 1189 | } else { | ||
| 1190 | full_path.push(path) | ||
| 1191 | } | ||
| 1192 | } | ||
| 1193 | |||
| 1194 | if worktree_relative_path.components().next().is_some() { | ||
| 1195 | full_path.push(&worktree_relative_path); | ||
| 1196 | } | ||
| 1197 | |||
| 1198 | full_path | ||
| 1199 | } | ||
| 1175 | } | 1200 | } |
| 1176 | 1201 | ||
| 1177 | impl LocalWorktree { | 1202 | impl LocalWorktree { |
| @@ -3229,27 +3254,7 @@ impl language::File for File { · 2051 unmodified lines | |||
| 3229 | } | 3254 | } |
| 3230 | 3255 | ||
| 3231 | fn full_path(&self, cx: &App) -> PathBuf { | 3256 | fn full_path(&self, cx: &App) -> PathBuf { |
| 3232 | let mut full_path = PathBuf::new(); | 3257 | self.worktree.read(cx).full_path(&self.path) |
| 3233 | let worktree = self.worktree.read(cx); | ||
| 3234 | |||
| 3235 | if worktree.is_visible() { | ||
| 3236 | full_path.push(worktree.root_name()); | ||
| 3237 | } else { | ||
| 3238 | let path = worktree.abs_path(); | ||
| 3239 | |||
| 3240 | if worktree.is_local() && path.starts_with(home_dir().as_path()) { | ||
| 3241 | full_path.push("~"); | ||
| 3242 | full_path.push(path.strip_prefix(home_dir().as_path()).unwrap()); | ||
| 3243 | } else { | ||
| 3244 | full_path.push(path) | ||
| 3245 | } | ||
| 3246 | } | ||
| 3247 | |||
| 3248 | if self.path.components().next().is_some() { | ||
| 3249 | full_path.push(&self.path); | ||
| 3250 | } | ||
| 3251 | |||
| 3252 | full_path | ||
| 3253 | } | 3258 | } |
| 3254 | 3259 | ||
| 3255 | /// Returns the last component of this handle's absolute path. If this handle refers to the root | 3260 | /// Returns the last component of this handle's absolute path. If this handle refers to the root |