Skip to content

Commit

Permalink
Merge pull request #17 from skillz/feature-chat-mentions-upgrade
Browse files Browse the repository at this point in the history
[#155997991] reloading trigger matrix when text is pasted in to inputbar
  • Loading branch information
armandgray authored Mar 15, 2018
2 parents 2e93b72 + 0947e9b commit d610337
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/MentionsTextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,10 @@ export default class MentionsTextInput extends Component {
}, 15);
}

isTextDifferenceGreaterThanOne(text1, text2) {
return !text1 && text2.length > 1 || text1.length < text2.length - 1;
}

onChangeText(text) {
if (this.isResetting) {
return;
Expand All @@ -535,6 +539,16 @@ export default class MentionsTextInput extends Component {
return;
}

if (this.isTextDifferenceGreaterThanOne(this.state.text, text)) {
// reset triggerMatrix for pasted text
this.reloadTriggerMatrix(text);
if (this.triggerMatrix.length > 0) {
const trigger = this.triggerMatrix[this.triggerMatrix.length - 1];
const keyword = text.slice(trigger[0], trigger[1] + 1);
this.props.triggerCallback(keyword, this.triggerMatrix, this.triggerMatrix.length - 1);
}
}

this.didTextChange = true;
this.setState({ text }, () => {
if (!this.isSelectionChangeHandled) {
Expand Down

0 comments on commit d610337

Please # to comment.