-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
[#12455] Limit word and character count for text editor. #12503
Conversation
Ready for review |
Hi @rexong, would it be possible to change it from a word limit to a character limit? Sorry for not pointing this out earlier on the original issue! The reasoning is:
My apologies again for not flagging this out sooner! I've also tested out your current solution, and I was able to save a response of over 500 words long... the screenshot below is after saving and refreshing the page: As a final comment, do make the changes only to the "Instructions" field in creating and editing a session, as mentioned in the issue. Setting the limit to every single text editor raises several other issues that we probably want to avoid. For example, an instructor might want to set the recommended word count for a question to be 1000 words. However, then students would be unable to hit that recommended word count. Do let me know if you have any questions about the above. |
I have made the following changes.
Ready for Review! |
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! Thanks for the changes (:
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.
Nice work! Just a minor comment. Would like both of your thoughts @rexong @weiquu
If we copy the text (via Select All and Copy) we've already entered in the editor and paste it back, the number of characters left is back to 2000.
If we cut the text instead, everything works as expected. Not sure if it's due to TinyMCE's API/the intended behaviour.
A video for both of your reference @ x2 speed please. Sorry it's a little lengthy, was thinking what to write and also show the behaviour.
2023-07-16.23-27-07.mp4
@domlimm Thank you for pointing this out. I will look into this issue. |
I have looked into the issue. It was because of my implementation of the New.video.mp4 |
Hi @rexong, sorry just noticed something else - the line breaks seem to disappear after the paste event has been stopped. I entered some text and some line breaks in between, and then copied the highlighted text: After pasting the highlighted text at the end, this is the result (notice the line breaks are gone, and the count still shows characters left): I believe it should be an issue with the Also noted a second issue: even if the paste is in the middle of the text, the substring that is removed is from the end of the text. For example, I've entered some text here and copied the "questions" word: After pasting the "questions" word into the whitespace in the centre, the text at the end (i.e. "hello") is gone: I'm wondering if this behaviour would be expected by the user... I would think that the behaviour should be the pasted text gets truncated instead. If you agree, my suggestion would be to get the substring of the pasted text instead and paste it at its intended location. This might solve the first issue as well since we're not setting the content of the whole editor (though I'm not too sure). |
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.
Nice work! Thank you for your contribution!
I will stick with this, it makes more sense. If I am using this editor and my end of text gets truncated, it could give a bad user experience. HW, let us know your thoughts. Always welcome other views! Not sure on the complexity of this implementation. But yes substring is the way to go as WQ suggested. I think we can close an eye on the performance for now as it's capped at 2KB worth of characters, performance shouldn't be impacted, is significant. |
@domlimm @weiquu To address the second issue, I am not too sure if there is a way for me to just get the paste content/ substring. I could probably compare the content before and after the paste event? |
Thanks @rexong for looking into the cause of the issue. I've tried some stuff but am unable to find a solution for the first issue... @domlimm any suggestions? If not, we can open a separate issue for it once this PR gets merged. Should also note that all other formatting (e.g. bold, strikethrough) also gets removed. For the second part on the truncation of the pasted text, I've done up a quick snippet to see if it's possible:
I ran a couple of tests and it seems to work, @rexong can I leave it to you to make sure that it works with any edge cases as well? I also didn't get to the part on setting the cursor; the cursor should probably be set to the end of the (truncated) pasted text. |
Hello @weiquu, thanks for the code snippet. I have added and tested the implementation. It seems to be working fine. In addition, I made some edits to set the cursor as well. Now the cursor will be set to wherever the pasted text ends when the character limit is reached. Here's a demo. TEAMMATES.-.Online.Peer.Feedback_Evaluation.System.for.Student.Team.Projects.-.Google.Chrome.2023-07-31.22-57-26.mp4 |
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! Pinging @domlimm to double check the change
Will review by tonight. |
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! Good job well done! Thank you for your efforts @rexong!
Sorry again for all the delays... Will merge once the checks pass.
@jasonqiu212 thanks Jason! 😄 |
Fixes #12455
Outline of Solution
Problem:
For all
rich-text-editor
, the user can enter unlimited text.Solution:
Limit the amount of text the user can enter.
rich-text-editor
.wordcount
plugin API from TinyMCE to get the word count that the user has entered.rich-text-editor
to show how many words are left.rich-text-editor
is enabled.Screenshot: