Skip to content

Commit

Permalink
comments: fix jumping cursor
Browse files Browse the repository at this point in the history
* these changes depending on thins PR: inveniosoftware/react-invenio-forms#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.
  • Loading branch information
Samk13 committed Jul 5, 2024
1 parent 8dec284 commit 9e7b652
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
}
Expand All @@ -52,8 +51,8 @@ const TimelineCommentEditor = ({
/>
<Container fluid className="ml-0-mobile mr-0-mobile fluid-mobile">
<RichEditor
value={commentContent}
onChange={(event, editor) => {
inputValue={commentContent}
onEditorChange={(event, editor) => {
setCommentContent(editor.getContent());
}}
minHeight={150}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ class TimelineCommentEvent extends Component {

{isEditing ? (
<RichEditor
value={event?.payload?.content}
onChange={(event, editor) => {
initialValue={event?.payload?.content}
inputValue={commentContent}
onEditorChange={(event, editor) => {
this.setState({ commentContent: editor.getContent() });
}}
minHeight={150}
Expand Down

0 comments on commit 9e7b652

Please sign in to comment.