fix: exclude YAML frontmatter from word count in Inspector panel

The DynamicPropertiesPanel had a local countWords that used a regex
(/^---[\s\S]*?---/) which could match dashes inside frontmatter values,
leaving part of the frontmatter in the body and inflating the count.

Replace with the canonical countWords from utils/wikilinks.ts which uses
splitFrontmatter (line-based indexOf) and correctly finds the closing
delimiter on its own line.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
lucaronin
2026-02-24 12:19:21 +01:00
parent 91c3f4bf16
commit d2c8d25add
3 changed files with 77 additions and 11 deletions

View File

@@ -5,6 +5,7 @@ import type { ParsedFrontmatter } from '../utils/frontmatter'
import { EditableValue, TagPillList } from './EditableValue'
import { Button } from '@/components/ui/button'
import { getTypeColor, getTypeLightColor } from '../utils/typeColors'
import { countWords } from '../utils/wikilinks'
const STATUS_STYLES: Record<string, { bg: string; color: string }> = {
Active: { bg: 'var(--accent-green-light)', color: 'var(--accent-green)' },
@@ -37,12 +38,6 @@ export function containsWikilinks(value: FrontmatterValue): boolean {
return false
}
function countWords(content: string | null): number {
if (!content) return 0
const stripped = content.replace(/^---[\s\S]*?---\n?/, '')
const words = stripped.trim().split(/\s+/).filter((w) => w.length > 0)
return words.length
}
function formatDate(timestamp: number | null): string {
if (!timestamp) return '\u2014'
@@ -238,7 +233,7 @@ export function DynamicPropertiesPanel({
const [editingKey, setEditingKey] = useState<string | null>(null)
const [showAddDialog, setShowAddDialog] = useState(false)
const wordCount = countWords(content)
const wordCount = countWords(content ?? '')
const propertyEntries = useMemo(() => {
return Object.entries(frontmatter)