From 9e7b652bbfdc435043fa7af9f0a08ca0730e629a Mon Sep 17 00:00:00 2001 From: Sam Arbid Date: Fri, 5 Jul 2024 14:48:05 +0200 Subject: [PATCH] comments: fix jumping cursor * these changes depending on thins PR: https://github.com/inveniosoftware/react-invenio-forms/pull/244 * align porperty naming as RichEditior wrongly named value instead of initialValue * change onchange to onEditorChange as recommended in the tinymce docs. * Change the prop value to inputValue, as the name value seems to conflict with other elements, causing the input text in edit mode to behave oddly. --- .../TimelineCommentEditor.js | 17 ++++++++--------- .../timelineEvents/TimelineCommentEvent.js | 5 +++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/invenio_requests/assets/semantic-ui/js/invenio_requests/timelineCommentEditor/TimelineCommentEditor.js b/invenio_requests/assets/semantic-ui/js/invenio_requests/timelineCommentEditor/TimelineCommentEditor.js index 4a4b6e46..81c2f2a9 100644 --- a/invenio_requests/assets/semantic-ui/js/invenio_requests/timelineCommentEditor/TimelineCommentEditor.js +++ b/invenio_requests/assets/semantic-ui/js/invenio_requests/timelineCommentEditor/TimelineCommentEditor.js @@ -27,15 +27,14 @@ const TimelineCommentEditor = ({ useSelector((state) => state.timeline.commentContentMaxLength) || 25000; const handleInit = (editor) => { editor.on("input", () => { - setCommentContent(editor.getContent()); - const charCount = editor.plugins.wordcount.body.getCharacterCount(); + // Using 'wordcount' plugin didn't give the real character count as it ignores HTML tags: + // const charCount = editor.plugins.wordcount.body.getCharacterCount(); + // Instead, we use getContent to include HTML tags in the count: + // If wordcount is redundant, we can remove it, though it might still be useful for plain text analysis. + const charCount = editor.getContent().length; setCharCount(charCount); if (charCount > commentContentMaxLength) { - setLocalError( - i18next.t( - `Character count exceeds the maximum limit of ${commentContentMaxLength} characters.` - ) - ); + setLocalError(i18next.t("Character count exceeds the maximum allowed limit.")); } else { setLocalError(""); } @@ -52,8 +51,8 @@ const TimelineCommentEditor = ({ /> { + inputValue={commentContent} + onEditorChange={(event, editor) => { setCommentContent(editor.getContent()); }} minHeight={150} diff --git a/invenio_requests/assets/semantic-ui/js/invenio_requests/timelineEvents/TimelineCommentEvent.js b/invenio_requests/assets/semantic-ui/js/invenio_requests/timelineEvents/TimelineCommentEvent.js index fd922ce1..ef933882 100644 --- a/invenio_requests/assets/semantic-ui/js/invenio_requests/timelineEvents/TimelineCommentEvent.js +++ b/invenio_requests/assets/semantic-ui/js/invenio_requests/timelineEvents/TimelineCommentEvent.js @@ -113,8 +113,9 @@ class TimelineCommentEvent extends Component { {isEditing ? ( { + initialValue={event?.payload?.content} + inputValue={commentContent} + onEditorChange={(event, editor) => { this.setState({ commentContent: editor.getContent() }); }} minHeight={150}