Skip to content

Commit a164a66

Browse files
stefansundinatilafassina
authored andcommitted
fix: paste moving the cursor to the end of the input element (#515)
* 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.
1 parent 94105bd commit a164a66

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/MentionsInput.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,17 @@ class MentionsInput extends React.Component {
386386
newPlainTextValue,
387387
getMentions(newValue, config)
388388
)
389+
390+
// Move the cursor position to the end of the pasted data
391+
const startOfMention = findStartOfMentionInPlainText(
392+
value,
393+
config,
394+
selectionStart
395+
)
396+
const nextPos =
397+
(startOfMention || selectionStart) +
398+
getPlainText(pastedMentions || pastedData, config).length
399+
this.setSelection(nextPos, nextPos)
389400
}
390401

391402
saveSelectionToClipboard(event) {

0 commit comments

Comments
 (0)