Commit ·
59895be
1
Parent(s): 55ce477
fix: Sentence count + reading time stats - Sentences: split by . ! ? ؟ and newlines (not just periods) - At least 1 sentence if text exists, 0 if empty - Reading time: 180 words/min for Arabic, shows 0 when empty - Minimum 1 minute when text exists
Browse files- src/js/format.js +11 -2
src/js/format.js
CHANGED
|
@@ -259,9 +259,18 @@ function initColorPicker(prefix, command, barId) {
|
|
| 259 |
function updateEnhancedStats() {
|
| 260 |
const text = getEditorText();
|
| 261 |
const charCount = text.length;
|
| 262 |
-
|
|
|
|
| 263 |
const words = text.trim().split(/\s+/).filter(w => w.length > 0).length;
|
| 264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
|
| 266 |
const charEl = document.getElementById('char-count');
|
| 267 |
const sentEl = document.getElementById('sentence-count');
|
|
|
|
| 259 |
function updateEnhancedStats() {
|
| 260 |
const text = getEditorText();
|
| 261 |
const charCount = text.length;
|
| 262 |
+
|
| 263 |
+
// Count sentences: split on Arabic/Latin sentence endings + newlines
|
| 264 |
const words = text.trim().split(/\s+/).filter(w => w.length > 0).length;
|
| 265 |
+
let sentences = 0;
|
| 266 |
+
if (text.trim().length > 0) {
|
| 267 |
+
// Split by: . ! ? ؟ ، ؛ and newlines
|
| 268 |
+
sentences = text.split(/[.!?؟\n]+/).filter(s => s.trim().length > 2).length;
|
| 269 |
+
if (sentences === 0) sentences = 1; // at least 1 if there's text
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
// Reading time: ~180 words/min for Arabic, show actual minutes
|
| 273 |
+
const readingTimeMinutes = words === 0 ? 0 : Math.max(1, Math.round(words / 180));
|
| 274 |
|
| 275 |
const charEl = document.getElementById('char-count');
|
| 276 |
const sentEl = document.getElementById('sentence-count');
|