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 = {
LINK: /(?:\[([^\]]+)\]\(([^\)]+)\))|\<(\w+:\/\/[^\>]+)\>/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 ROOM_REGEX = /#\S+:\S+/g;
let EMOJI_REGEX = null;
window.EMOJI_REGEX = EMOJI_REGEX = new RegExp(emojione.unicodeRegexp, 'g');
const EMOJI_REGEX = new RegExp(emojione.unicodeRegexp, 'g');
export function contentStateToHTML(contentState: ContentState): string {
return contentState.getBlockMap().map((block) => {

View File

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

View File

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

View File

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

View File

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