💄 selection count

This commit is contained in:
2026-05-22 22:07:17 +10:00
parent c56cc15207
commit 6b9eb388ba
4 changed files with 32 additions and 2 deletions

View File

@@ -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