Skip to content
Open
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
60 changes: 31 additions & 29 deletions src/MentionsInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ const propTypes = {
forceSuggestionsAboveCursor: PropTypes.bool,
ignoreAccents: PropTypes.bool,
a11ySuggestionsListLabel: PropTypes.string,

value: PropTypes.string,
onKeyDown: PropTypes.func,
customSuggestionsContainer: PropTypes.func,
onSelect: PropTypes.func,
onBlur: PropTypes.func,
onChange: PropTypes.func,
setPastedFiles: PropTypes.func,
suggestionsPortalHost:
typeof Element === 'undefined'
? PropTypes.any
Expand Down Expand Up @@ -113,6 +113,7 @@ class MentionsInput extends React.Component {
onKeyDown: () => null,
onSelect: () => null,
onBlur: () => null,
setPastedFiles: () => null,
}

constructor(props) {
Expand Down Expand Up @@ -370,35 +371,36 @@ class MentionsInput extends React.Component {

const pastedMentions = event.clipboardData.getData('text/react-mentions')
const pastedData = event.clipboardData.getData('text/plain')
const pastedFiles = (event.clipboardData || event.originalEvent.clipboardData).files;
if (pastedFiles.length) {
this.props.setPastedFiles(pastedFiles);
} else {
const newValue = spliceString(
value,
markupStartIndex,
markupEndIndex,
pastedMentions || pastedData
).replace(/\r/g, '')
const newPlainTextValue = getPlainText(newValue, config)
const eventMock = { target: { ...event.target, value: newValue } }
this.executeOnChange(
eventMock,
newValue,
newPlainTextValue,
getMentions(newValue, config)
)

const newValue = spliceString(
value,
markupStartIndex,
markupEndIndex,
pastedMentions || pastedData
).replace(/\r/g, '')

const newPlainTextValue = getPlainText(newValue, config)

const eventMock = { target: { ...event.target, value: newValue } }

this.executeOnChange(
eventMock,
newValue,
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)
// 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