fix: parse numeric YAML values as numbers so _favorite_index persists

parseScalar() returned all non-boolean values as strings, causing
contentToEntryPatch() to map _favorite_index: 2 → favoriteIndex: null
(typeof "2" !== "number"). Every editor autosave then reset the
in-memory favorite index, breaking drag-to-reorder persistence.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Test
2026-04-03 18:40:18 +02:00
parent 188cd7af8b
commit ab3de7eecd
3 changed files with 46 additions and 0 deletions

View File

@@ -468,6 +468,24 @@ describe('contentToEntryPatch', () => {
const content = '---\ntype: Note\ncustom: value\n---\n'
expect(contentToEntryPatch(content)).toEqual({ isA: 'Note' })
})
it('preserves _favorite_index as a number (not null)', () => {
const content = '---\n_favorite: true\n_favorite_index: 2\n---\nBody'
const patch = contentToEntryPatch(content)
expect(patch.favorite).toBe(true)
expect(patch.favoriteIndex).toBe(2)
})
it('preserves _favorite_index: 0 as number 0', () => {
const content = '---\n_favorite: true\n_favorite_index: 0\n---\nBody'
const patch = contentToEntryPatch(content)
expect(patch.favoriteIndex).toBe(0)
})
it('preserves order as a number', () => {
const content = '---\ntype: Type\norder: 3\n---\n'
expect(contentToEntryPatch(content)).toEqual({ isA: 'Type', order: 3 })
})
})
describe('todayDateString', () => {

View File

@@ -2,6 +2,33 @@ import { describe, it, expect } from 'vitest'
import { parseFrontmatter, detectFrontmatterState } from './frontmatter'
describe('parseFrontmatter', () => {
describe('numeric values', () => {
it('parses integer values as numbers', () => {
const fm = parseFrontmatter('---\n_favorite_index: 2\n---\nBody')
expect(fm['_favorite_index']).toBe(2)
})
it('parses zero as number 0', () => {
const fm = parseFrontmatter('---\n_favorite_index: 0\n---\nBody')
expect(fm['_favorite_index']).toBe(0)
})
it('parses float values as numbers', () => {
const fm = parseFrontmatter('---\norder: 3.5\n---\nBody')
expect(fm['order']).toBe(3.5)
})
it('parses negative numbers', () => {
const fm = parseFrontmatter('---\norder: -1\n---\nBody')
expect(fm['order']).toBe(-1)
})
it('does not parse quoted numbers as numbers', () => {
const fm = parseFrontmatter('---\nversion: "42"\n---\nBody')
expect(fm['version']).toBe('42')
})
})
describe('boolean-like Yes/No values', () => {
it('parses Archived: Yes as true', () => {
const fm = parseFrontmatter('---\nArchived: Yes\n---\nBody')

View File

@@ -26,6 +26,7 @@ function parseScalar(value: string): FrontmatterValue {
const lower = clean.toLowerCase()
if (lower === 'true' || lower === 'yes') return true
if (lower === 'false' || lower === 'no') return false
if (clean === value && /^-?\d+(\.\d+)?$/.test(clean)) return Number(clean)
return clean
}