fix: code cleanup, fix getCurrentCommand

pull/21833/head
Aviral Dasgupta 2016-07-04 21:44:35 +05:30
parent cccc58b47f
commit 30b7efd585
5 changed files with 16 additions and 15 deletions

View File

@ -33,13 +33,12 @@ const STYLES = {
const MARKDOWN_REGEX = { const MARKDOWN_REGEX = {
LINK: /(?:\[([^\]]+)\]\(([^\)]+)\))|\<(\w+:\/\/[^\>]+)\>/g, LINK: /(?:\[([^\]]+)\]\(([^\)]+)\))|\<(\w+:\/\/[^\>]+)\>/g,
ITALIC: /([\*_])([\w\s]+?)\1/g, ITALIC: /([\*_])([\w\s]+?)\1/g,
BOLD: /([\*_])\1([\w\s]+?)\1\1/g BOLD: /([\*_])\1([\w\s]+?)\1\1/g,
}; };
const USERNAME_REGEX = /@\S+:\S+/g; const USERNAME_REGEX = /@\S+:\S+/g;
const ROOM_REGEX = /#\S+:\S+/g; const ROOM_REGEX = /#\S+:\S+/g;
let EMOJI_REGEX = null; const EMOJI_REGEX = new RegExp(emojione.unicodeRegexp, 'g');
window.EMOJI_REGEX = EMOJI_REGEX = new RegExp(emojione.unicodeRegexp, 'g');
export function contentStateToHTML(contentState: ContentState): string { export function contentStateToHTML(contentState: ContentState): string {
return contentState.getBlockMap().map((block) => { return contentState.getBlockMap().map((block) => {

View File

@ -18,6 +18,8 @@ export default class AutocompleteProvider {
return null; return null;
} }
this.commandRegex.lastIndex = 0;
let match; let match;
while ((match = this.commandRegex.exec(query)) != null) { while ((match = this.commandRegex.exec(query)) != null) {
let matchStart = match.index, let matchStart = match.index,
@ -33,7 +35,6 @@ export default class AutocompleteProvider {
}; };
} }
} }
this.commandRegex.lastIndex = 0;
return { return {
command: null, command: null,
range: { range: {

View File

@ -10,10 +10,10 @@ export function TextualCompletion({
description: ?string description: ?string
}) { }) {
return ( return (
<div className="mx_Autocomplete_Completion"> <div style={{width: '100%'}}>
<span>{title}</span> <span>{title}</span>
<em>{subtitle}</em> <em>{subtitle}</em>
<span style={{color: 'gray', float: 'right'}}>{description}</span> <span style={{color: 'gray'}}>{description}</span>
</div> </div>
); );
} }

View File

@ -520,9 +520,6 @@ module.exports = React.createClass({
_updateTabCompleteList: function() { _updateTabCompleteList: function() {
var cli = MatrixClientPeg.get(); var cli = MatrixClientPeg.get();
console.log('_updateTabCompleteList');
console.log(this.state.room);
console.trace();
if (!this.state.room) { if (!this.state.room) {
return; return;

View File

@ -80,8 +80,9 @@ export default class Autocomplete extends React.Component {
* @returns {boolean} whether confirmation was handled * @returns {boolean} whether confirmation was handled
*/ */
onConfirm(): boolean { onConfirm(): boolean {
if (this.countCompletions() === 0) if (this.countCompletions() === 0) {
return false; return false;
}
let selectedCompletion = this.state.completionList[this.state.selectionOffset]; let selectedCompletion = this.state.completionList[this.state.selectionOffset];
this.props.onConfirm(selectedCompletion.range, selectedCompletion.completion); this.props.onConfirm(selectedCompletion.range, selectedCompletion.completion);
@ -103,11 +104,11 @@ export default class Autocomplete extends React.Component {
let componentPosition = position; let componentPosition = position;
position++; position++;
let onMouseOver = () => this.setSelection(componentPosition), let onMouseOver = () => this.setSelection(componentPosition);
onClick = () => { let onClick = () => {
this.setSelection(componentPosition); this.setSelection(componentPosition);
this.onConfirm(); this.onConfirm();
}; };
return ( return (
<div key={i} <div key={i}
@ -151,4 +152,7 @@ export default class Autocomplete extends React.Component {
Autocomplete.propTypes = { Autocomplete.propTypes = {
// the query string for which to show autocomplete suggestions // the query string for which to show autocomplete suggestions
query: React.PropTypes.string.isRequired, query: React.PropTypes.string.isRequired,
// method invoked with range and text content when completion is confirmed
onConfirm: React.PropTypes.func.isRequired,
}; };