diff --git a/app/src/uri/mod.rs b/app/src/uri/mod.rs index 54b766fe8a..b27335f43f 100644 --- a/app/src/uri/mod.rs +++ b/app/src/uri/mod.rs @@ -1223,8 +1223,8 @@ enum OpenFileAction { /// Pure routing decision for `open_file`. Extracted so it can be unit-tested without /// standing up a full `AppContext`. -fn classify_open_file_action(path: &Path) -> OpenFileAction { - if is_markdown_file(path) { +fn classify_open_file_action(path: &Path, prefer_markdown_viewer: bool) -> OpenFileAction { + if is_markdown_file(path) && prefer_markdown_viewer { OpenFileAction::Notebook } else if is_runnable_shell_script(path) { OpenFileAction::ExecuteInSession @@ -1243,7 +1243,7 @@ fn can_open_file_editor_path(path: &Path) -> bool { } /// Handle an incoming `file://` URL. -/// * Markdown files are opened as notebook panes. +/// * Markdown files are opened as notebook panes when the viewer preference is enabled. /// * For directories, open a new session at the directory path. /// * For other files, open a new session at the parent directory path, then possibly execute the /// file. @@ -1253,7 +1253,15 @@ fn open_file(window_id: Option, path: PathBuf, ctx: &mut AppContext) { .map(|view_id| (window_id, view_id)) }); - let action = classify_open_file_action(&path); + #[cfg(feature = "local_fs")] + let prefer_markdown_viewer = { + use crate::util::file::external_editor::EditorSettings; + *EditorSettings::as_ref(ctx).prefer_markdown_viewer + }; + #[cfg(not(feature = "local_fs"))] + let prefer_markdown_viewer = true; + + let action = classify_open_file_action(&path, prefer_markdown_viewer); if action == OpenFileAction::Notebook { if let Some((primary_window_id, root_view_id)) = primary_window_and_view { diff --git a/app/src/uri/uri_tests.rs b/app/src/uri/uri_tests.rs index 2705e41b46..ee7aadf964 100644 --- a/app/src/uri/uri_tests.rs +++ b/app/src/uri/uri_tests.rs @@ -743,7 +743,7 @@ fn test_open_file_executable_sh_routes_to_execute() { let p = dir.path().join("run.sh"); std::fs::write(&p, b"#!/bin/sh\n:\n").unwrap(); std::fs::set_permissions(&p, std::fs::Permissions::from_mode(0o755)).unwrap(); - let action = classify_open_file_action(&p); + let action = classify_open_file_action(&p, true); assert_eq!(action, OpenFileAction::ExecuteInSession); } @@ -755,7 +755,7 @@ fn test_open_file_non_executable_sh_routes_to_editor() { let p = dir.path().join("view.sh"); std::fs::write(&p, b"#!/bin/sh\n:\n").unwrap(); std::fs::set_permissions(&p, std::fs::Permissions::from_mode(0o644)).unwrap(); - assert_eq!(classify_open_file_action(&p), OpenFileAction::Editor); + assert_eq!(classify_open_file_action(&p, true), OpenFileAction::Editor); } #[test] @@ -768,7 +768,7 @@ fn test_open_file_executable_bash_zsh_fish_route_to_execute() { std::fs::write(&p, b"#!/bin/sh\n:\n").unwrap(); std::fs::set_permissions(&p, std::fs::Permissions::from_mode(0o755)).unwrap(); assert_eq!( - classify_open_file_action(&p), + classify_open_file_action(&p, true), OpenFileAction::ExecuteInSession, "{name} should route to ExecuteInSession", ); @@ -776,11 +776,22 @@ fn test_open_file_executable_bash_zsh_fish_route_to_execute() { } #[test] -fn test_open_file_markdown_unchanged() { +fn test_open_file_markdown_routes_to_notebook_when_viewer_enabled() { let dir = tempfile::tempdir().unwrap(); let p = dir.path().join("README.md"); std::fs::write(&p, b"# hi\n").unwrap(); - assert_eq!(classify_open_file_action(&p), OpenFileAction::Notebook); + assert_eq!( + classify_open_file_action(&p, true), + OpenFileAction::Notebook + ); +} + +#[test] +fn test_open_file_markdown_routes_to_editor_when_viewer_disabled() { + let dir = tempfile::tempdir().unwrap(); + let p = dir.path().join("README.md"); + std::fs::write(&p, b"# hi\n").unwrap(); + assert_eq!(classify_open_file_action(&p, false), OpenFileAction::Editor); } #[test] @@ -789,7 +800,7 @@ fn test_open_file_rust_source_still_opens_in_editor() { let dir = tempfile::tempdir().unwrap(); let p = dir.path().join("main.rs"); std::fs::write(&p, b"fn main() {}\n").unwrap(); - assert_eq!(classify_open_file_action(&p), OpenFileAction::Editor); + assert_eq!(classify_open_file_action(&p, true), OpenFileAction::Editor); } #[test] @@ -825,7 +836,7 @@ fn test_open_file_editor_binary_file_is_rejected() { fn test_open_file_directory_routes_to_session() { let dir = tempfile::tempdir().unwrap(); assert_eq!( - classify_open_file_action(dir.path()), + classify_open_file_action(dir.path(), true), OpenFileAction::ExecuteInSession ); } @@ -841,7 +852,7 @@ fn test_open_file_non_runnable_shebang_routes_to_editor() { let p = dir.path().join("noext"); std::fs::write(&p, b"#!/bin/sh\necho hi\n").unwrap(); std::fs::set_permissions(&p, std::fs::Permissions::from_mode(0o644)).unwrap(); - assert_eq!(classify_open_file_action(&p), OpenFileAction::Editor); + assert_eq!(classify_open_file_action(&p, true), OpenFileAction::Editor); } #[test]