Этот коммит содержится в:
Reed Garmsen
2015-07-14 19:59:09 -07:00
родитель 9747053a4e
Коммит c5c4c0b4de

Просмотреть файл

@@ -31,41 +31,26 @@ module.exports = React.createClass({
e.preventDefault(); e.preventDefault();
var tempSelectedMention = -1 var tempSelectedMention = -1
self.refs['mention' + self.state.selectedMention].deselect();
if (!self.getSelection(self.state.selectedMention)) { if (e.which === 38) {
while (self.getSelection(++tempSelectedMention)) { if (self.getSelection(self.state.selectedMention - 1))
if (self.state.selectedUsername === self.refs['mention' + tempSelectedMention].props.username) { self.setState({ selectedMention: self.state.selectedMention - 1, selectedUsername: self.refs['mention' + (self.state.selectedMention - 1)].props.username });
this.refs['mention' + tempSelectedMention].select(); else {
this.setState({ selectedMention: tempSelectedMention }); while (self.getSelection(++tempSelectedMention))
break; ; //Need to find the top of the list
} self.setState({ selectedMention: tempSelectedMention - 1, selectedUsername: self.refs['mention' + (tempSelectedMention - 1)].props.username });
} }
} }
else { else {
self.refs['mention' + self.state.selectedMention].deselect(); if (self.getSelection(self.state.selectedMention + 1))
if (e.which === 38) { self.setState({ selectedMention: self.state.selectedMention + 1, selectedUsername: self.refs['mention' + (self.state.selectedMention + 1)].props.username });
if (self.getSelection(self.state.selectedMention - 1)) else
self.setState({ selectedMention: self.state.selectedMention - 1, selectedUsername: self.refs['mention' + (self.state.selectedMention - 1)].props.username }); self.setState({ selectedMention: 0, selectedUsername: self.refs.mention0.props.username });
else {
while (self.getSelection(++tempSelectedMention))
; //Need to find the top of the list
self.setState({ selectedMention: tempSelectedMention - 1, selectedUsername: self.refs['mention' + (tempSelectedMention - 1)].props.username });
}
}
else {
if (self.getSelection(self.state.selectedMention + 1))
self.setState({ selectedMention: self.state.selectedMention + 1, selectedUsername: self.refs['mention' + (self.state.selectedMention + 1)].props.username });
else
self.setState({ selectedMention: 0, selectedUsername: self.refs.mention0.props.username });
}
} }
self.refs['mention' + self.state.selectedMention].select();
self.refs['mention' + self.state.selectedMention].select();
self.scrollToMention(e.which, tempSelectedMention); self.scrollToMention(e.which, tempSelectedMention);
} }
else if (e.which === 46 || e.which === 8) {
self.setState({ lessText: true });
}
} }
); );
$(document).click(function(e) { $(document).click(function(e) {
@@ -89,7 +74,7 @@ module.exports = React.createClass({
if (this.state.selectedUsername !== "" && (!this.getSelection(this.state.selectedMention) || this.state.selectedUsername !== this.refs['mention' + this.state.selectedMention].props.username)) { if (this.state.selectedUsername !== "" && (!this.getSelection(this.state.selectedMention) || this.state.selectedUsername !== this.refs['mention' + this.state.selectedMention].props.username)) {
var tempSelectedMention = -1; var tempSelectedMention = -1;
var foundMatch = false; var foundMatch = false;
while (!this.state.lessText && this.getSelection(++tempSelectedMention)) { while (tempSelectedMention < this.state.selectedMention && this.getSelection(++tempSelectedMention)) {
if (this.state.selectedUsername === this.refs['mention' + tempSelectedMention].props.username) { if (this.state.selectedUsername === this.refs['mention' + tempSelectedMention].props.username) {
this.refs['mention' + tempSelectedMention].select(); this.refs['mention' + tempSelectedMention].select();
this.setState({ selectedMention: tempSelectedMention }); this.setState({ selectedMention: tempSelectedMention });
@@ -99,7 +84,7 @@ module.exports = React.createClass({
} }
if (this.refs.mention0 != undefined && !foundMatch) { if (this.refs.mention0 != undefined && !foundMatch) {
this.refs.mention0.select(); this.refs.mention0.select();
this.setState({ selectedMention: 0, selectedUsername: this.refs.mention0.props.username, lessText: false }); this.setState({ selectedMention: 0, selectedUsername: this.refs.mention0.props.username });
} }
} }
else if (this.refs['mention' + this.state.selectedMention] != undefined) { else if (this.refs['mention' + this.state.selectedMention] != undefined) {
@@ -136,8 +121,7 @@ module.exports = React.createClass({
this.refs['mention' + listId].select(); this.refs['mention' + listId].select();
}, },
getSelection: function(listId) { getSelection: function(listId) {
var mention = this.refs['mention' + listId]; if (!this.refs['mention' + listId])
if (!mention)
return false; return false;
else else
return true; return true;
@@ -182,7 +166,7 @@ module.exports = React.createClass({
return false; return false;
}, },
getInitialState: function() { getInitialState: function() {
return { excludeUsers: [], mentionText: "-1", selectedMention: 0, selectedUsername: "", lessText: false }; return { excludeUsers: [], mentionText: "-1", selectedMention: 0, selectedUsername: "" };
}, },
render: function() { render: function() {
var mentionText = this.state.mentionText; var mentionText = this.state.mentionText;