Skip to content

Commit

Permalink
Fixed native undo/redo (#676)
Browse files Browse the repository at this point in the history
* Fixed native undo/redo

* uneeded .gitignore additions removed

* readded *.log to gitignore, was removed by accident

---------

Co-authored-by: Sigrsig <[email protected]>
  • Loading branch information
byTimo and Sigrsig authored Jun 29, 2023
1 parent 32d9728 commit 4ef52dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-kangaroos-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-mentions": patch
---

Fixed native undo/redo in case the input was not focused before the operation
14 changes: 12 additions & 2 deletions src/MentionsInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,23 @@ class MentionsInput extends React.Component {

let newPlainTextValue = ev.target.value

let selectionStartBefore = this.state.selectionStart;
if(selectionStartBefore == null) {
selectionStartBefore = ev.target.selectionStart;
}

let selectionEndBefore = this.state.selectionEnd;
if(selectionEndBefore == null) {
selectionEndBefore = ev.target.selectionEnd;
}

// Derive the new value to set by applying the local change in the textarea's plain text
let newValue = applyChangeToValue(
value,
newPlainTextValue,
{
selectionStartBefore: this.state.selectionStart,
selectionEndBefore: this.state.selectionEnd,
selectionStartBefore,
selectionEndBefore,
selectionEndAfter: ev.target.selectionEnd,
},
config
Expand Down

1 comment on commit 4ef52dd

@vercel
Copy link

@vercel vercel bot commented on 4ef52dd Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

react-mentions – ./

react-mentions.vercel.app
react-mentions-signavio.vercel.app
react-mentions-git-master-signavio.vercel.app

Please sign in to comment.