💄 average word count
This commit is contained in:
@@ -43,6 +43,16 @@ function formatWordCount(n: number): string {
|
|||||||
return String(n)
|
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 {
|
export function AnalysisToolbar(): JSX.Element {
|
||||||
const {
|
const {
|
||||||
activeFilePath,
|
activeFilePath,
|
||||||
@@ -219,6 +229,7 @@ export function AnalysisToolbar(): JSX.Element {
|
|||||||
const totalCount = passiveCount + consistencyCount + styleCount + showTellCount + critiqueCount
|
const totalCount = passiveCount + consistencyCount + styleCount + showTellCount + critiqueCount
|
||||||
const anyActive = Boolean(analysisMode)
|
const anyActive = Boolean(analysisMode)
|
||||||
const docWordCount = countWords(activeFileContent)
|
const docWordCount = countWords(activeFileContent)
|
||||||
|
const avgSentenceLen = activeFileContent ? computeAvgSentenceLength(activeFileContent) : null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="toolbar">
|
<div className="toolbar">
|
||||||
@@ -373,11 +384,17 @@ export function AnalysisToolbar(): JSX.Element {
|
|||||||
{activeFilePath && (
|
{activeFilePath && (
|
||||||
<span
|
<span
|
||||||
className="toolbar-wordcount"
|
className="toolbar-wordcount"
|
||||||
title={`This document: ${docWordCount.toLocaleString()} words · Entire project: ${projectWordCount.toLocaleString()} words`}
|
title={`This document: ${docWordCount.toLocaleString()} words · Entire project: ${projectWordCount.toLocaleString()} words${avgSentenceLen !== null ? ` · Avg sentence: ${avgSentenceLen} words` : ''}`}
|
||||||
>
|
>
|
||||||
{formatWordCount(docWordCount)}
|
{formatWordCount(docWordCount)}
|
||||||
<span className="toolbar-wordcount-sep">/</span>
|
<span className="toolbar-wordcount-sep">/</span>
|
||||||
{formatWordCount(projectWordCount)}
|
{formatWordCount(projectWordCount)}
|
||||||
|
{avgSentenceLen !== null && (
|
||||||
|
<>
|
||||||
|
<span className="toolbar-wordcount-sep">·</span>
|
||||||
|
{avgSentenceLen}w
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{isDirty && (
|
{isDirty && (
|
||||||
|
|||||||
Reference in New Issue
Block a user