diff --git a/src/renderer/components/Editor/MarkdownEditor.tsx b/src/renderer/components/Editor/MarkdownEditor.tsx
index 58aca2d..9aa2ab3 100644
--- a/src/renderer/components/Editor/MarkdownEditor.tsx
+++ b/src/renderer/components/Editor/MarkdownEditor.tsx
@@ -697,7 +697,15 @@ export function MarkdownEditor(): JSX.Element {
}
if (update.selectionSet) {
const { from, to } = update.state.selection.main
- setHasSelection(from !== to)
+ const hasNonEmpty = from !== to
+ setHasSelection(hasNonEmpty)
+ if (hasNonEmpty) {
+ const sel = update.state.sliceDoc(from, to)
+ const words = sel.trim() === '' ? 0 : sel.trim().split(/\s+/).length
+ useEditorStore.getState().setSelectionWordCount(words)
+ } else {
+ useEditorStore.getState().setSelectionWordCount(null)
+ }
}
// When the user Cmd+Z's through an Apply, invertedEffects fires a
// setAnnotationsEffect restoring the old list inside CM. Sync that
diff --git a/src/renderer/components/Toolbar/AnalysisToolbar.tsx b/src/renderer/components/Toolbar/AnalysisToolbar.tsx
index 69fd510..e34c669 100644
--- a/src/renderer/components/Toolbar/AnalysisToolbar.tsx
+++ b/src/renderer/components/Toolbar/AnalysisToolbar.tsx
@@ -79,7 +79,8 @@ export function AnalysisToolbar(): JSX.Element {
outlineOpen,
toggleOutline,
revisionPanelOpen,
- toggleRevisionPanel
+ toggleRevisionPanel,
+ selectionWordCount
} = useEditorStore()
const [analyzeOpen, setAnalyzeOpen] = useState(false)
@@ -381,6 +382,11 @@ export function AnalysisToolbar(): JSX.Element {
A+
+ {selectionWordCount !== null && (
+
+ {formatWordCount(selectionWordCount)} sel
+
+ )}
{activeFilePath && (
void
+ selectionWordCount: number | null
+ setSelectionWordCount: (count: number | null) => void
// Editor font size
fontSize: number
@@ -593,6 +595,9 @@ export const useEditorStore = create((set, get) => ({
projectWordCount: 0,
setProjectWordCount: (projectWordCount) => set({ projectWordCount }),
+ selectionWordCount: null as number | null,
+ setSelectionWordCount: (count: number | null) => set({ selectionWordCount: count }),
+
revisionPanelOpen: false,
toggleRevisionPanel: () => set((s) => ({ revisionPanelOpen: !s.revisionPanelOpen })),