Skip to content

Commit

Permalink
Fix #12325
Browse files Browse the repository at this point in the history
- In ReportActionItemMessageEdit.js change updateDraft's setState
- In ReportActionCompose.js change updateComment's setState
- In both changes, verify if the input has been manipulated.
If yes, mantain cursor position from previous state
  • Loading branch information
AndreasBBS committed Nov 16, 2022
1 parent 8d295c5 commit 8188200
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,21 @@ class ReportActionCompose extends React.Component {
*/
updateComment(comment, shouldDebounceSaveComment) {
const newComment = EmojiUtils.replaceEmojis(comment);
this.setState({
isCommentEmpty: !!newComment.match(/^(\s|`)*$/),
value: newComment,
this.setState((prevState) => {
let newState = {
isCommentEmpty: !!newComment.match(/^(\s|`)*$/),
value: newComment
}

if(comment !== newComment) {
const remainder = prevState.value.slice(prevState.selection.end).length
newState.selection = {
start: newComment.length - remainder,
end: newComment.length - remainder
}
}

return newState
});

// Indicate that draft has been created.
Expand Down
15 changes: 14 additions & 1 deletion src/pages/home/report/ReportActionItemMessageEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,20 @@ class ReportActionItemMessageEdit extends React.Component {
*/
updateDraft(draft) {
const newDraft = EmojiUtils.replaceEmojis(draft);
this.setState({draft: newDraft});

this.setState((prevState) => {
let newState = {draft: newDraft}

if(draft !== newDraft) {
const remainder = prevState.draft.slice(prevState.selection.end).length
newState.selection = {
start: newDraft.length - remainder,
end: newDraft.length - remainder
}
}

return newState
});

// This component is rendered only when draft is set to a non-empty string. In order to prevent component
// unmount when user deletes content of textarea, we set previous message instead of empty string.
Expand Down

0 comments on commit 8188200

Please sign in to comment.