Merge pull request #1177 from matrix-org/luke/fix-rte-prefix-matching
Only match users by matchgin displayname or user ID prefixes
This commit is contained in:
commit
0af77e8913
2 changed files with 10 additions and 3 deletions
|
@ -69,6 +69,12 @@ export default class QueryMatcher {
|
||||||
if (this.options.shouldMatchWordsOnly === undefined) {
|
if (this.options.shouldMatchWordsOnly === undefined) {
|
||||||
this.options.shouldMatchWordsOnly = true;
|
this.options.shouldMatchWordsOnly = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// By default, match anywhere in the string being searched. If enabled, only return
|
||||||
|
// matches that are prefixed with the query.
|
||||||
|
if (this.options.shouldMatchPrefix === undefined) {
|
||||||
|
this.options.shouldMatchPrefix = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setObjects(objects: Array<Object>) {
|
setObjects(objects: Array<Object>) {
|
||||||
|
@ -87,7 +93,7 @@ export default class QueryMatcher {
|
||||||
resultKey = resultKey.replace(/[^\w]/g, '');
|
resultKey = resultKey.replace(/[^\w]/g, '');
|
||||||
}
|
}
|
||||||
const index = resultKey.indexOf(query);
|
const index = resultKey.indexOf(query);
|
||||||
if (index !== -1) {
|
if (index !== -1 && (!this.options.shouldMatchPrefix || index === 0)) {
|
||||||
results.push({key, index});
|
results.push({key, index});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -37,10 +37,11 @@ export default class UserProvider extends AutocompleteProvider {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super(USER_REGEX, {
|
super(USER_REGEX, {
|
||||||
keys: ['name', 'userId'],
|
keys: ['name'],
|
||||||
});
|
});
|
||||||
this.matcher = new FuzzyMatcher([], {
|
this.matcher = new FuzzyMatcher([], {
|
||||||
keys: ['name', 'userId'],
|
keys: ['name'],
|
||||||
|
shouldMatchPrefix: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue