mirror of https://github.com/vector-im/riot-web
parent
6328a60301
commit
5c57b9ab9b
|
@ -64,14 +64,14 @@ export default class AutocompleteProvider {
|
||||||
commandRegex = this.forcedCommandRegex || /\S+/g;
|
commandRegex = this.forcedCommandRegex || /\S+/g;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commandRegex == null) {
|
if (commandRegex === null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
commandRegex.lastIndex = 0;
|
commandRegex.lastIndex = 0;
|
||||||
|
|
||||||
let match;
|
let match;
|
||||||
while ((match = commandRegex.exec(query)) != null) {
|
while ((match = commandRegex.exec(query)) !== null) {
|
||||||
const start = match.index;
|
const start = match.index;
|
||||||
const end = start + match[0].length;
|
const end = start + match[0].length;
|
||||||
if (selection.start <= end && selection.end >= start) {
|
if (selection.start <= end && selection.end >= start) {
|
||||||
|
|
|
@ -49,7 +49,7 @@ export default class CommunityProvider extends AutocompleteProvider {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCompletions(query: string, selection: ISelectionRange, force: boolean = false): Promise<ICompletion[]> {
|
async getCompletions(query: string, selection: ISelectionRange, force = false): Promise<ICompletion[]> {
|
||||||
const BaseAvatar = sdk.getComponent('views.avatars.BaseAvatar');
|
const BaseAvatar = sdk.getComponent('views.avatars.BaseAvatar');
|
||||||
|
|
||||||
// Disable autocompletions when composing commands because of various issues
|
// Disable autocompletions when composing commands because of various issues
|
||||||
|
|
|
@ -98,14 +98,14 @@ export default class UserProvider extends AutocompleteProvider {
|
||||||
this.users = null;
|
this.users = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
async getCompletions(query: string, selection: ISelectionRange, force = false): Promise<ICompletion[]> {
|
async getCompletions(rawQuery: string, selection: ISelectionRange, force = false): Promise<ICompletion[]> {
|
||||||
const MemberAvatar = sdk.getComponent('views.avatars.MemberAvatar');
|
const MemberAvatar = sdk.getComponent('views.avatars.MemberAvatar');
|
||||||
|
|
||||||
// lazy-load user list into matcher
|
// lazy-load user list into matcher
|
||||||
if (this.users === null) this._makeUsers();
|
if (this.users === null) this._makeUsers();
|
||||||
|
|
||||||
let completions = [];
|
let completions = [];
|
||||||
const {command, range} = this.getCurrentCommand(query, selection, force);
|
const {command, range} = this.getCurrentCommand(rawQuery, selection, force);
|
||||||
|
|
||||||
if (!command) return completions;
|
if (!command) return completions;
|
||||||
|
|
||||||
|
|
|
@ -281,7 +281,7 @@ export default class Autocomplete extends React.PureComponent<IProps, IState> {
|
||||||
render() {
|
render() {
|
||||||
let position = 1;
|
let position = 1;
|
||||||
const renderedCompletions = this.state.completions.map((completionResult, i) => {
|
const renderedCompletions = this.state.completions.map((completionResult, i) => {
|
||||||
const completions = completionResult.completions.map((completion, i) => {
|
const completions = completionResult.completions.map((completion, j) => {
|
||||||
const selected = position === this.state.selectionOffset;
|
const selected = position === this.state.selectionOffset;
|
||||||
const className = classNames('mx_Autocomplete_Completion', {selected});
|
const className = classNames('mx_Autocomplete_Completion', {selected});
|
||||||
const componentPosition = position;
|
const componentPosition = position;
|
||||||
|
@ -292,7 +292,7 @@ export default class Autocomplete extends React.PureComponent<IProps, IState> {
|
||||||
};
|
};
|
||||||
|
|
||||||
return React.cloneElement(completion.component, {
|
return React.cloneElement(completion.component, {
|
||||||
"key": i,
|
"key": j,
|
||||||
"ref": `completion${componentPosition}`,
|
"ref": `completion${componentPosition}`,
|
||||||
"id": generateCompletionDomId(componentPosition - 1), // 0 index the completion IDs
|
"id": generateCompletionDomId(componentPosition - 1), // 0 index the completion IDs
|
||||||
className,
|
className,
|
||||||
|
|
Loading…
Reference in New Issue