From f21f7eff4592a149536f3fbd00c22fd198d1832c Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 25 Jun 2018 09:32:51 +0100 Subject: [PATCH] add word boundary to Community,Room,User provider regexps to stop the autocompleter firing mid-word and remove any unused capture groups Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/autocomplete/CommunityProvider.js | 3 ++- src/autocomplete/RoomProvider.js | 3 ++- src/autocomplete/UserProvider.js | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/autocomplete/CommunityProvider.js b/src/autocomplete/CommunityProvider.js index 6b5438e8c8..6bcf1a02fd 100644 --- a/src/autocomplete/CommunityProvider.js +++ b/src/autocomplete/CommunityProvider.js @@ -1,5 +1,6 @@ /* Copyright 2018 New Vector Ltd +Copyright 2018 Michael Telatynski <7t3chguy@gmail.com> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -26,7 +27,7 @@ import {makeGroupPermalink} from "../matrix-to"; import type {Completion, SelectionRange} from "./Autocompleter"; import FlairStore from "../stores/FlairStore"; -const COMMUNITY_REGEX = /(?=\+)(\S*)/g; +const COMMUNITY_REGEX = /\B\+\S*/g; function score(query, space) { const index = space.indexOf(query); diff --git a/src/autocomplete/RoomProvider.js b/src/autocomplete/RoomProvider.js index c222ae95d4..4e41a4221a 100644 --- a/src/autocomplete/RoomProvider.js +++ b/src/autocomplete/RoomProvider.js @@ -2,6 +2,7 @@ Copyright 2016 Aviral Dasgupta Copyright 2017 Vector Creations Ltd Copyright 2017, 2018 New Vector Ltd +Copyright 2018 Michael Telatynski <7t3chguy@gmail.com> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -28,7 +29,7 @@ import _sortBy from 'lodash/sortBy'; import {makeRoomPermalink} from "../matrix-to"; import type {Completion, SelectionRange} from "./Autocompleter"; -const ROOM_REGEX = /(?=#)(\S*)/g; +const ROOM_REGEX = /\B#\S*/g; function score(query, space) { const index = space.indexOf(query); diff --git a/src/autocomplete/UserProvider.js b/src/autocomplete/UserProvider.js index 85837d5ebb..97cbae2e63 100644 --- a/src/autocomplete/UserProvider.js +++ b/src/autocomplete/UserProvider.js @@ -3,6 +3,7 @@ Copyright 2016 Aviral Dasgupta Copyright 2017 Vector Creations Ltd Copyright 2017, 2018 New Vector Ltd +Copyright 2018 Michael Telatynski <7t3chguy@gmail.com> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -30,7 +31,7 @@ import type {Room, RoomMember} from 'matrix-js-sdk'; import {makeUserPermalink} from "../matrix-to"; import type {SelectionRange} from "./Autocompleter"; -const USER_REGEX = /@\S*/g; +const USER_REGEX = /\B@\S*/g; export default class UserProvider extends AutocompleteProvider { users: Array = null;