Skip to content

Commit

Permalink
fix: paste moving the cursor to the end of the input element (#515)
Browse files Browse the repository at this point in the history
* Fix pasting always putting the cursor at the end of the input element.

* Fix for when you copy a mention only (pastedData is an empty string). Try this by putting the cursor in a mention (without selecting any text) and copy, and then paste.
  • Loading branch information
stefansundin authored and atilafassina committed Apr 20, 2022
1 parent 94105bd commit a164a66
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/MentionsInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,17 @@ class MentionsInput extends React.Component {
newPlainTextValue,
getMentions(newValue, config)
)

// Move the cursor position to the end of the pasted data
const startOfMention = findStartOfMentionInPlainText(
value,
config,
selectionStart
)
const nextPos =
(startOfMention || selectionStart) +
getPlainText(pastedMentions || pastedData, config).length
this.setSelection(nextPos, nextPos)
}

saveSelectionToClipboard(event) {
Expand Down

1 comment on commit a164a66

@vercel
Copy link

@vercel vercel bot commented on a164a66 Apr 20, 2022

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.