diff --git a/app/src/actions/Settings.ts b/app/src/actions/Settings.ts index 257e5e5d..f6ac8eee 100644 --- a/app/src/actions/Settings.ts +++ b/app/src/actions/Settings.ts @@ -45,12 +45,12 @@ export const storeSettings = () => async (dispatch: Dispatch, getState: () export const setAutoExpandLimit = (autoExpandLimit: number = 0) => - (dispatch: Dispatch) => { - dispatch({ - autoExpandLimit, - type: ActionTypes.SETTINGS_SET_AUTO_EXPAND_LIMIT, - }) - } + (dispatch: Dispatch) => { + dispatch({ + autoExpandLimit, + type: ActionTypes.SETTINGS_SET_AUTO_EXPAND_LIMIT, + }) + } export const setTimeLocale = (timeLocale: string) => (dispatch: Dispatch) => { dispatch({ @@ -85,13 +85,13 @@ export const toggleHighlightTopicUpdates = () => (dispatch: Dispatch) => { export const setTopicOrder = (topicOrder: TopicOrder = TopicOrder.none) => - (dispatch: Dispatch) => { - dispatch({ - topicOrder, - type: ActionTypes.SETTINGS_SET_TOPIC_ORDER, - }) - dispatch(storeSettings()) - } + (dispatch: Dispatch) => { + dispatch({ + topicOrder, + type: ActionTypes.SETTINGS_SET_TOPIC_ORDER, + }) + dispatch(storeSettings()) + } export const filterTopics = (filterStr: string) => (dispatch: Dispatch, getState: () => AppState) => { const { tree } = getState().connection @@ -106,10 +106,13 @@ export const filterTopics = (filterStr: string) => (dispatch: Dispatch, get return } - const topicFilter = filterStr.toLowerCase() + const topicFilter = filterStr + // code heavily inspired by https://stackoverflow.com/a/32402438 + const escapeRegex = (str: string) => str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1') + const reTopicFilter = new RegExp(topicFilter.split('+').map(escapeRegex).join('[^/]+')) const nodeFilter = (node: q.TreeNode): boolean => { - const topicMatches = node.path().toLowerCase().indexOf(topicFilter) !== -1 + const topicMatches = node.path().search(reTopicFilter) !== -1 if (topicMatches) { return true } @@ -127,7 +130,8 @@ export const filterTopics = (filterStr: string) => (dispatch: Dispatch, get .filter(nodeFilter) .map((node: q.TreeNode) => { const clone = node.unconnectedClone() - q.TreeNodeFactory.insertNodeAtPosition(node.path().split('/'), clone) + const edgeNames = node.path().replace(reTopicFilter, filterStr).split('/') + q.TreeNodeFactory.insertNodeAtPosition(edgeNames, clone) return clone.firstNode() }) .reduce((a: q.TreeNode, b: q.TreeNode) => { @@ -167,4 +171,4 @@ export const toggleTheme = () => (dispatch: Dispatch, getState: () => AppSt : ActionTypes.SETTINGS_SET_THEME_LIGHT, }) dispatch(storeSettings()) -} +} \ No newline at end of file