From 363b7a49155f9d90787b507c6d129a43a8adfe44 Mon Sep 17 00:00:00 2001 From: Alex Hernandez Date: Fri, 1 May 2026 12:29:36 +1000 Subject: [PATCH] :lipstick: average word count --- .../components/Toolbar/AnalysisToolbar.tsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/renderer/components/Toolbar/AnalysisToolbar.tsx b/src/renderer/components/Toolbar/AnalysisToolbar.tsx index cf5876b..69fd510 100644 --- a/src/renderer/components/Toolbar/AnalysisToolbar.tsx +++ b/src/renderer/components/Toolbar/AnalysisToolbar.tsx @@ -43,6 +43,16 @@ function formatWordCount(n: number): string { return String(n) } +function computeAvgSentenceLength(text: string): number | null { + const sentences = text + .split(/[.!?]+/) + .map(s => s.trim()) + .filter(s => s.length > 0) + if (sentences.length === 0) return null + const totalWords = sentences.reduce((sum, s) => sum + countWords(s), 0) + return Math.round((totalWords / sentences.length) * 10) / 10 +} + export function AnalysisToolbar(): JSX.Element { const { activeFilePath, @@ -219,6 +229,7 @@ export function AnalysisToolbar(): JSX.Element { const totalCount = passiveCount + consistencyCount + styleCount + showTellCount + critiqueCount const anyActive = Boolean(analysisMode) const docWordCount = countWords(activeFileContent) + const avgSentenceLen = activeFileContent ? computeAvgSentenceLength(activeFileContent) : null return (
@@ -373,11 +384,17 @@ export function AnalysisToolbar(): JSX.Element { {activeFilePath && ( {formatWordCount(docWordCount)} / {formatWordCount(projectWordCount)} + {avgSentenceLen !== null && ( + <> + · + {avgSentenceLen}w + + )} )} {isDirty && (