feat: rename file on save when title slug doesn't match filename

When Cmd+S is pressed, after saving content, checks if the note's
title slug differs from its current filename. If so, triggers
rename_note to update the file on disk, tabs, breadcrumbs, and
wikilinks. Adds needsRenameOnSave() utility with tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
lucaronin
2026-03-11 17:18:37 +01:00
parent 761d6dc3b5
commit e0bf514f5d
3 changed files with 35 additions and 7 deletions

View File

@@ -5,6 +5,7 @@ import { isTauri, mockInvoke } from '../mock-tauri'
import type { VaultEntry } from '../types'
import {
slugify,
needsRenameOnSave,
buildNewEntry,
generateUntitledName,
entryMatchesTarget,
@@ -94,6 +95,22 @@ describe('slugify', () => {
})
})
describe('needsRenameOnSave', () => {
it('returns true when filename does not match title slug', () => {
expect(needsRenameOnSave('My New Note', 'untitled-note.md')).toBe(true)
expect(needsRenameOnSave('Run good ads for newsletter', 'untitled-note-9.md')).toBe(true)
})
it('returns false when filename matches title slug', () => {
expect(needsRenameOnSave('My Note', 'my-note.md')).toBe(false)
expect(needsRenameOnSave('Hello World', 'hello-world.md')).toBe(false)
})
it('returns false for untitled note with matching slug', () => {
expect(needsRenameOnSave('Untitled note', 'untitled-note.md')).toBe(false)
})
})
describe('buildNewEntry', () => {
it('creates a VaultEntry with correct fields', () => {
const entry = buildNewEntry({