Skip to content

Commit 2242cbc

Browse files
authored
fix: More inclusive word counting that handles hyphenated words and more languages
1 parent 56479da commit 2242cbc

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

  • admin/src/lexical/plugins/WordCountPlugin

admin/src/lexical/plugins/WordCountPlugin/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const WordCountPlugin: React.FC<WordCountPluginProps> = ({ limit, charset = 'UTF
7272
const root = $getRoot();
7373
const text = root.getTextContent();
7474

75-
const words = text.match(/\b\w+\b/g)?.length || 0;
75+
const words = text.trim().split(/\s+/).filter(Boolean).length;
7676
const chars = text.length;
7777

7878
setWordCount(words);

0 commit comments

Comments
 (0)