Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed native undo/redo #676

Merged
merged 4 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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