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) <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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(<BreadcrumbBar entry={baseEntry} {...defaultProps} rawMode={true} onToggleRaw={onToggleRaw} forceRawMode={true} />)
|
||||
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(<BreadcrumbBar entry={baseEntry} {...defaultProps} rawMode={false} onToggleRaw={onToggleRaw} forceRawMode={false} />)
|
||||
expect(screen.getByTitle('Raw editor')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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<BreadcrumbBarProps, 'wordCount'>) {
|
||||
@@ -112,7 +114,7 @@ function BreadcrumbActions({ entry, showDiffToggle, diffMode, diffLoading, onTog
|
||||
<GitBranch size={16} />
|
||||
</button>
|
||||
)}
|
||||
<RawToggleButton rawMode={rawMode} onToggleRaw={onToggleRaw} />
|
||||
{!forceRawMode && <RawToggleButton rawMode={rawMode} onToggleRaw={onToggleRaw} />}
|
||||
<button
|
||||
className="flex items-center justify-center border-none bg-transparent p-0 text-muted-foreground"
|
||||
style={DISABLED_ICON_STYLE}
|
||||
|
||||
@@ -222,7 +222,7 @@ export function EditorContent({
|
||||
<ActiveTabBreadcrumb
|
||||
activeTab={activeTab}
|
||||
barRef={breadcrumbBarRef}
|
||||
props={{ diffMode, diffContent, onToggleDiff, rawMode: effectiveRawMode, onToggleRaw, ...breadcrumbProps }}
|
||||
props={{ diffMode, diffContent, onToggleDiff, rawMode: effectiveRawMode, onToggleRaw, forceRawMode: isNonMarkdownText, ...breadcrumbProps }}
|
||||
/>
|
||||
{isTrashed && (
|
||||
<TrashedNoteBanner
|
||||
|
||||
Reference in New Issue
Block a user