Repository navigation
fix: word count overcounts on whitespace and newlines - #148
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesWord Count Handling
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Fixes word counting in the long-form textarea by treating any run of whitespace (spaces, tabs, newlines) as a single separator, preventing overcounting when users enter multiple spaces or line breaks.
Changes:
- Update
wordCountcalculation to split on\s+instead of a single literal space. - Introduce an intermediate
trimmedValto ensure leading/trailing whitespace doesn’t affect the count.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Variable wordCount in 'LongFormInput.tsx' was calculated with 'value.trim().split(" ")'. This is an issue as splitting on a single literal space means any consecutive space would count as another entry in the split array, unnecessarily increasing the count. Code is modified to depend on regex expressions where the split handles any length of whitespace rather than a single literal whitespace.
A test file was created and deleted to test this. The results are presented in the attached images


I appreciate you guys giving me the opportunity to fix this error and I hope it works on your end!
Sincerely,
Karthik Kumar
kkumar07@terpmail.umd.edu
Summary by CodeRabbit