From ef17e7b3b199b91ea2e8d07fdbf2ba8d6b3f2768 Mon Sep 17 00:00:00 2001 From: lucaronin Date: Sun, 5 Apr 2026 12:59:19 +0200 Subject: [PATCH] fix: hide Raw toggle for non-markdown files forced into raw editor Non-markdown text files (.yml, .yaml, .json, etc.) are already forced into raw editor mode via effectiveRawMode. This hides the Raw toggle button in the breadcrumb bar for those files since toggling is not applicable. Adds tests for classify_file_kind and forceRawMode behavior. Co-Authored-By: Claude Opus 4.6 (1M context) --- src-tauri/src/vault/mod_tests.rs | 30 +++++++++++++++++++++++++++ src/components/BreadcrumbBar.test.tsx | 13 ++++++++++++ src/components/BreadcrumbBar.tsx | 6 ++++-- src/components/EditorContent.tsx | 2 +- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/vault/mod_tests.rs b/src-tauri/src/vault/mod_tests.rs index 14fd600f..2570a775 100644 --- a/src-tauri/src/vault/mod_tests.rs +++ b/src-tauri/src/vault/mod_tests.rs @@ -1521,6 +1521,36 @@ fn test_non_yml_file_uses_filename_as_title() { assert_eq!(entry.title, "notes.txt"); } +#[test] +fn test_classify_file_kind_yml_is_text() { + assert_eq!(classify_file_kind(Path::new("views/active-projects.yml")), "text"); + assert_eq!(classify_file_kind(Path::new("config.yaml")), "text"); + assert_eq!(classify_file_kind(Path::new("data.json")), "text"); + assert_eq!(classify_file_kind(Path::new("script.py")), "text"); + assert_eq!(classify_file_kind(Path::new("readme.txt")), "text"); +} + +#[test] +fn test_classify_file_kind_md_is_markdown() { + assert_eq!(classify_file_kind(Path::new("note.md")), "markdown"); + assert_eq!(classify_file_kind(Path::new("README.markdown")), "markdown"); +} + +#[test] +fn test_classify_file_kind_unknown_is_binary() { + assert_eq!(classify_file_kind(Path::new("photo.png")), "binary"); + assert_eq!(classify_file_kind(Path::new("archive.zip")), "binary"); +} + +#[test] +fn test_non_md_file_gets_text_file_kind() { + let dir = TempDir::new().unwrap(); + create_test_file(dir.path(), "views/my-view.yml", "name: My View\nicon: rocket\n"); + let entry = super::parse_non_md_file(&dir.path().join("views/my-view.yml"), None).unwrap(); + assert_eq!(entry.file_kind, "text"); + assert_eq!(entry.title, "My View"); +} + // Frontmatter update/delete tests are in frontmatter.rs // save_image tests are in vault/image.rs // purge_trash tests are in vault/trash.rs diff --git a/src/components/BreadcrumbBar.test.tsx b/src/components/BreadcrumbBar.test.tsx index d9401765..aafc5b1b 100644 --- a/src/components/BreadcrumbBar.test.tsx +++ b/src/components/BreadcrumbBar.test.tsx @@ -174,4 +174,17 @@ describe('BreadcrumbBar — raw editor toggle', () => { fireEvent.click(screen.getByTitle('Raw editor')) expect(onToggleRaw).toHaveBeenCalledOnce() }) + + it('hides raw toggle when forceRawMode is true (non-markdown file)', () => { + const onToggleRaw = vi.fn() + render() + expect(screen.queryByTitle('Raw editor')).not.toBeInTheDocument() + expect(screen.queryByTitle('Back to editor')).not.toBeInTheDocument() + }) + + it('shows raw toggle when forceRawMode is false (markdown file)', () => { + const onToggleRaw = vi.fn() + render() + expect(screen.getByTitle('Raw editor')).toBeInTheDocument() + }) }) diff --git a/src/components/BreadcrumbBar.tsx b/src/components/BreadcrumbBar.tsx index 1e9c8347..fa414dd9 100644 --- a/src/components/BreadcrumbBar.tsx +++ b/src/components/BreadcrumbBar.tsx @@ -26,6 +26,8 @@ interface BreadcrumbBarProps { onToggleDiff: () => void rawMode?: boolean onToggleRaw?: () => void + /** When true, raw mode is forced (non-markdown file) — hide the toggle. */ + forceRawMode?: boolean showAIChat?: boolean onToggleAIChat?: () => void inspectorCollapsed?: boolean @@ -58,7 +60,7 @@ function RawToggleButton({ rawMode, onToggleRaw }: { rawMode?: boolean; onToggle } function BreadcrumbActions({ entry, showDiffToggle, diffMode, diffLoading, onToggleDiff, - rawMode, onToggleRaw, + rawMode, onToggleRaw, forceRawMode, showAIChat, onToggleAIChat, inspectorCollapsed, onToggleInspector, onToggleFavorite, onToggleOrganized, onTrash, onRestore, onArchive, onUnarchive, }: Omit) { @@ -112,7 +114,7 @@ function BreadcrumbActions({ entry, showDiffToggle, diffMode, diffLoading, onTog )} - + {!forceRawMode && }