Set the working directory according to the editor file path (#14688)
Kernels now launch in the same directory as the script invoking them, similar to notebook behavior.  Release Notes: - N/A
This commit is contained in:
parent
f5f4578422
commit
ba4fa17b83
4 changed files with 52 additions and 17 deletions
|
@ -131,7 +131,7 @@ use std::{
|
|||
mem,
|
||||
num::NonZeroU32,
|
||||
ops::{ControlFlow, Deref, DerefMut, Not as _, Range, RangeInclusive},
|
||||
path::Path,
|
||||
path::{Path, PathBuf},
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
time::{Duration, Instant},
|
||||
|
@ -10386,6 +10386,22 @@ impl Editor {
|
|||
cx.notify();
|
||||
}
|
||||
|
||||
pub fn working_directory(&self, cx: &WindowContext) -> Option<PathBuf> {
|
||||
if let Some(buffer) = self.buffer().read(cx).as_singleton() {
|
||||
if let Some(file) = buffer.read(cx).file().and_then(|f| f.as_local()) {
|
||||
if let Some(dir) = file.abs_path(cx).parent() {
|
||||
return Some(dir.to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(project_path) = buffer.read(cx).project_path(cx) {
|
||||
return Some(project_path.path.to_path_buf());
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn reveal_in_finder(&mut self, _: &RevealInFileManager, cx: &mut ViewContext<Self>) {
|
||||
if let Some(buffer) = self.buffer().read(cx).as_singleton() {
|
||||
if let Some(file) = buffer.read(cx).file().and_then(|f| f.as_local()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue