Skip to content

Commit 91dd783

Browse files
committed
Apply execute-dir logic in refresh!
1 parent 87c78d8 commit 91dd783

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/QuartoNotebookWorker/src/refresh.jl

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
11
function refresh!(path, original_options, options = original_options)
2-
# Current directory should always start out as the directory of the
3-
# notebook file, which is not necessarily right initially if the parent
4-
# process was started from a different directory to the notebook.
5-
cd(dirname(path))
62
task_local_storage()[:SOURCE_PATH] = path
3+
4+
# We check the `execute-dir` key in the options,
5+
if haskey(options, "project") && haskey(options["project"], "execute-dir")
6+
ed = options["project"]["execute-dir"]
7+
if ed == "directory"
8+
println("cd(dirname(path))")
9+
cd(dirname(path))
10+
elseif ed == "project"
11+
# TODO: this doesn't seem right. How does one get the root path of the project here?
12+
# Maybe piggyback on `options` with some ridiculous identifier?
13+
println("cd(NotebookState.PROJECT[])")
14+
if isfile(NotebookState.PROJECT[])
15+
cd(dirname(NotebookState.PROJECT[]))
16+
elseif isdir(NotebookState.PROJECT[])
17+
cd(NotebookState.PROJECT[])
18+
else
19+
@warn "Project path not found: $(NotebookState.PROJECT[])"
20+
end
21+
else
22+
println("cd(abspath(options[\"execute-dir\"])) => cd($(abspath(ed)))")
23+
cd(abspath(ed))
24+
end
25+
else
26+
# Current directory should always start out as the directory of the
27+
# notebook file, which is not necessarily right initially if the parent
28+
# process was started from a different directory to the notebook.
29+
cd(dirname(path))
30+
end
731

832
# Reset back to the original project environment if it happens to
933
# have changed during cell evaluation.

0 commit comments

Comments
 (0)