diff --git a/packages/app-desktop/gui/NoteContentPropertiesDialog.tsx b/packages/app-desktop/gui/NoteContentPropertiesDialog.tsx index 7b7ba8aad3..f65ffda465 100644 --- a/packages/app-desktop/gui/NoteContentPropertiesDialog.tsx +++ b/packages/app-desktop/gui/NoteContentPropertiesDialog.tsx @@ -31,13 +31,15 @@ function markupToHtml() { } // eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied -function countElements(text: string, wordSetter: Function, characterSetter: Function, characterNoSpaceSetter: Function, lineSetter: Function) { +function countElements(text: string, wordSetter: Function, characterSetter: Function, characterNoSpaceSetter: Function, cjkCharacterSetter: React.Dispatch>, lineSetter: Function) { // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied Countable.count(text, (counter: any) => { wordSetter(counter.words); characterSetter(counter.all); characterNoSpaceSetter(counter.characters); }); + const cjkMatches = text.match(/[\p{Script=Han}\p{Script=Bopomofo}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/gu); + cjkCharacterSetter(cjkMatches ? cjkMatches.length : 0); lineSetter(text === '' ? 0 : text.split('\n').length); } @@ -58,23 +60,25 @@ export default function NoteContentPropertiesDialog(props: NoteContentProperties const [words, setWords] = useState(0); const [characters, setCharacters] = useState(0); const [charactersNoSpace, setCharactersNoSpace] = useState(0); + const [cjkCharacters, setCjkCharacters] = useState(0); // For source with Markdown syntax stripped out const [strippedLines, setStrippedLines] = useState(0); const [strippedWords, setStrippedWords] = useState(0); const [strippedCharacters, setStrippedCharacters] = useState(0); const [strippedCharactersNoSpace, setStrippedCharactersNoSpace] = useState(0); + const [strippedCjkCharacters, setStrippedCjkCharacters] = useState(0); const [strippedReadTime, setStrippedReadTime] = useState(0); // This amount based on the following paper: // https://www.researchgate.net/publication/332380784_How_many_words_do_we_read_per_minute_A_review_and_meta-analysis_of_reading_rate const wordsPerMinute = 250; useEffect(() => { - countElements(props.text, setWords, setCharacters, setCharactersNoSpace, setLines); + countElements(props.text, setWords, setCharacters, setCharactersNoSpace, setCjkCharacters, setLines); }, [props.text]); useEffect(() => { const strippedText: string = markupToHtml().stripMarkup(props.markupLanguage, props.text); - countElements(strippedText, setStrippedWords, setStrippedCharacters, setStrippedCharactersNoSpace, setStrippedLines); + countElements(strippedText, setStrippedWords, setStrippedCharacters, setStrippedCharactersNoSpace, setStrippedCjkCharacters, setStrippedLines); // eslint-disable-next-line @seiyab/react-hooks/exhaustive-deps -- Old code before rule was applied }, [props.text]); @@ -88,6 +92,7 @@ export default function NoteContentPropertiesDialog(props: NoteContentProperties words: words, characters: characters, charactersNoSpace: charactersNoSpace, + cjkCharacters: cjkCharacters, }; const strippedTextProperties: TextPropertiesMap = { @@ -99,12 +104,14 @@ export default function NoteContentPropertiesDialog(props: NoteContentProperties words: strippedWords, characters: strippedCharacters, charactersNoSpace: strippedCharactersNoSpace, + cjkCharacters: strippedCjkCharacters, }; const keyToLabel: KeyToLabelMap = { words: _('Words'), characters: _('Characters'), charactersNoSpace: _('Characters excluding spaces'), + cjkCharacters: _('Chinese/Japanese/Korean characters'), lines: _('Lines'), }; @@ -147,6 +154,7 @@ export default function NoteContentPropertiesDialog(props: NoteContentProperties ); for (const key in textProperties) { + if (key === 'cjkCharacters' && textProperties[key] === 0 && strippedTextProperties[key] === 0) continue; const comp = createTableBodyRow(key, textProperties[key], strippedTextProperties[key]); tableBodyComps.push(comp); } diff --git a/packages/tools/cspell/dictionary4.txt b/packages/tools/cspell/dictionary4.txt index 8b2664de34..9dde9a1d91 100644 --- a/packages/tools/cspell/dictionary4.txt +++ b/packages/tools/cspell/dictionary4.txt @@ -219,4 +219,5 @@ tablatures tablature REVO REVOGB +Bopomofo Linkosed \ No newline at end of file