mirror of https://github.com/vector-im/riot-web
fix: code cleanup, fix getCurrentCommand
parent
cccc58b47f
commit
30b7efd585
|
@ -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) => {
|
||||||
|
|
|
@ -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: {
|
||||||
|
|
|
@ -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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue