mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
Update the word count modal (#27068)
GitOrigin-RevId: c4d11bda020e435bcf8b6daec253cedb37df0252
This commit is contained in:
@@ -5,7 +5,7 @@ import { debugConsole } from '@/utils/debugging'
|
||||
import { findPreambleExtent } from '@/features/word-count-modal/utils/find-preamble-extent'
|
||||
import { Segmenters } from './segmenters'
|
||||
|
||||
const whiteSpaceRe = /^\s$/
|
||||
// const whiteSpaceRe = /^\s$/
|
||||
|
||||
type Context = 'text' | 'header' | 'abstract' | 'caption' | 'footnote' | 'other'
|
||||
|
||||
@@ -301,9 +301,8 @@ export const countWordsInFile = (
|
||||
for (const [context, text] of Object.entries(texts)) {
|
||||
const counter = counters[context as Context]
|
||||
|
||||
// TODO: replace - and _ with a word character if hyphenated words should be counted as one word?
|
||||
|
||||
for (const value of segmenters.word.segment(
|
||||
// replace - and _ with a word character, so that hyphenated words are counted as one word
|
||||
text.replace(/\w[-_]\w/g, 'aaa')
|
||||
)) {
|
||||
if (value.isWordLike) {
|
||||
@@ -311,13 +310,14 @@ export const countWordsInFile = (
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: count hyphens as characters?
|
||||
|
||||
for (const value of segmenters.character.segment(text)) {
|
||||
for (const _value of segmenters.character.segment(
|
||||
// replace multiple spaces with a single space
|
||||
text.replace(/\s+/, ' ').trim()
|
||||
)) {
|
||||
// TODO: option for whether to include whitespace?
|
||||
if (!whiteSpaceRe.test(value.segment)) {
|
||||
data[counter.character]++
|
||||
}
|
||||
// if (!whiteSpaceRe.test(value.segment)) {
|
||||
data[counter.character]++
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user