-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix #888 - Wrong word count due splitting #3226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉 Congrats on your first PR being approved!
@@ -511,7 +511,7 @@ class MarkdownNoteDetail extends React.Component { | |||
exportAsTxt={this.exportAsTxt} | |||
exportAsHtml={this.exportAsHtml} | |||
exportAsPdf={this.exportAsPdf} | |||
wordCount={note.content.split(' ').length} | |||
wordCount={note.content.replace(/\r?\n?\s+/g, ' ').trim().split(' ').length} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello ! :)
I think it can be replaced by:
note.content.trim().split(/\r?\n?\s+/g).length
or even
note.content.trim().split(/\s+/g).length
since \s
includes cariage returns and new lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thamara Can you change your code to the above suggestion for more concise code? Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I'd use the split(/s+/g)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make the suggested change. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
Description
Word count on Note Details was incorrect computed by counting words splitted by space. In the event of one word per line, the count was incorrect:
This was fixed by converting line breaks into spaces and then splitting them for count:
Issue fixed
#888
Type of changes
Checklist: