Skip to content

Commit

Permalink
Fixed native undo/redo (signavio#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

0 comments on commit 4ef52dd

Please sign in to comment.