From c783a6dc56527d2df5eda2ec0af866660058a54b Mon Sep 17 00:00:00 2001 From: Richard Wu Date: Tue, 3 Nov 2026 22:10:01 +0800 Subject: [PATCH] fix: stop treating .txt as a supported document Plain text was listed in the open, locate and link handlers but the file dialog never offered it for new files, and a .txt opened through the app behaved like Markdown without being one. Drop the extension everywhere so the supported set is one list: md, markdown, mdown, mkd. --- src/main.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index cbeaca4..4c84baa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2797,6 +2797,16 @@ mod tests { assert!(html.contains("
")); } + #[test] + fn only_markdown_extensions_are_supported_documents() { + for name in ["note.md", "note.MARKDOWN", "note.mdown", "note.mkd"] { + assert!(is_supported_document(Path::new(name)), "{name}"); + } + for name in ["note.txt", "note.html", "note", "note.md.bak"] { + assert!(!is_supported_document(Path::new(name)), "{name}"); + } + } + #[test] fn file_urls_only_open_existing_supported_documents() { let dir = temp_test_dir("document-links"); @@ -3824,7 +3834,7 @@ fn is_supported_document(path: &Path) -> bool { .map(|extension| { matches!( extension.to_string_lossy().to_ascii_lowercase().as_str(), - "md" | "markdown" | "mdown" | "mkd" | "txt" + "md" | "markdown" | "mdown" | "mkd" ) }) .unwrap_or(false) @@ -4947,7 +4957,7 @@ fn main() { return; } if let Some(paths) = rfd::FileDialog::new() - .add_filter("Markdown", &["md", "markdown", "mdown", "mkd", "txt"]) + .add_filter("Markdown", &["md", "markdown", "mdown", "mkd"]) .pick_files() { let _ = proxy.send_event(UserEvent::OpenPaths( @@ -5190,7 +5200,7 @@ fn main() { } TaoEvent::UserEvent(UserEvent::LocateTab(window_id, id)) => { if let Some(path) = rfd::FileDialog::new() - .add_filter("Markdown", &["md", "markdown", "mdown", "mkd", "txt"]) + .add_filter("Markdown", &["md", "markdown", "mdown", "mkd"]) .pick_file() { if let Some((other_id, other_tab)) = find_open_path(&app, &path) {