From 284799c76a4df99abac00daa460eeb57e7118054 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 5 Jan 2022 09:17:35 +0000 Subject: [PATCH 1/3] Fix spotlight cmd-k wrongly expanding left panel --- src/components/structures/MatrixChat.tsx | 2 ++ src/components/structures/RoomSearch.tsx | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index 9728fa72546..f37fbdc443d 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -794,6 +794,8 @@ export default class MatrixChat extends React.PureComponent { }); break; case 'focus_room_filter': // for CtrlOrCmd+K to work by expanding the left panel first + if (SettingsStore.getValue("feature_spotlight")) break; // don't expand if spotlight enabled + // fallthrough case 'show_left_panel': this.setState({ collapseLhs: false, diff --git a/src/components/structures/RoomSearch.tsx b/src/components/structures/RoomSearch.tsx index cd4f022341d..0244d193247 100644 --- a/src/components/structures/RoomSearch.tsx +++ b/src/components/structures/RoomSearch.tsx @@ -93,11 +93,11 @@ export default class RoomSearch extends React.PureComponent { private onAction = (payload: ActionPayload) => { if (payload.action === Action.ViewRoom && payload.clear_search) { this.clearInput(); - } else if (payload.action === 'focus_room_filter' && this.inputRef.current) { + } else if (payload.action === 'focus_room_filter') { if (SettingsStore.getValue("feature_spotlight")) { this.openSpotlight(); } else { - this.inputRef.current.focus(); + this.inputRef.current?.focus(); } } }; @@ -109,8 +109,12 @@ export default class RoomSearch extends React.PureComponent { }; private openSearch = () => { - defaultDispatcher.dispatch({ action: "show_left_panel" }); - defaultDispatcher.dispatch({ action: "focus_room_filter" }); + if (SettingsStore.getValue("feature_spotlight")) { + this.openSpotlight(); + } else { + defaultDispatcher.dispatch({ action: "show_left_panel" }); + defaultDispatcher.dispatch({ action: "focus_room_filter" }); + } }; private onChange = () => { From 52c9da8d0df07152a3cdc92c19d95418fdbf7290 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 5 Jan 2022 09:18:01 +0000 Subject: [PATCH 2/3] Remove unused code --- src/components/structures/SearchBox.tsx | 37 +------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/src/components/structures/SearchBox.tsx b/src/components/structures/SearchBox.tsx index ea36f41033d..359762cfc1c 100644 --- a/src/components/structures/SearchBox.tsx +++ b/src/components/structures/SearchBox.tsx @@ -37,11 +37,6 @@ interface IProps extends HTMLProps { autoFocus?: boolean; initialValue?: string; collapsed?: boolean; - - // If true, the search box will focus and clear itself - // on room search focus action (it would be nicer to take - // this functionality out, but not obvious how that would work) - enableRoomSearchFocus?: boolean; } interface IState { @@ -51,13 +46,8 @@ interface IState { @replaceableComponent("structures.SearchBox") export default class SearchBox extends React.Component { - private dispatcherRef: string; private search = createRef(); - static defaultProps: Partial = { - enableRoomSearchFocus: false, - }; - constructor(props: IProps) { super(props); @@ -67,31 +57,6 @@ export default class SearchBox extends React.Component { }; } - public componentDidMount(): void { - this.dispatcherRef = dis.register(this.onAction); - } - - public componentWillUnmount(): void { - dis.unregister(this.dispatcherRef); - } - - private onAction = (payload): void => { - if (!this.props.enableRoomSearchFocus) return; - - switch (payload.action) { - case Action.ViewRoom: - if (this.search.current && payload.clear_search) { - this.clearSearch(); - } - break; - case 'focus_room_filter': - if (this.search.current) { - this.search.current.focus(); - } - break; - } - }; - private onChange = (): void => { if (!this.search.current) return; this.setState({ searchTerm: this.search.current.value }); @@ -137,7 +102,7 @@ export default class SearchBox extends React.Component { public render(): JSX.Element { /* eslint @typescript-eslint/no-unused-vars: ["error", { "ignoreRestSiblings": true }] */ const { onSearch, onCleared, onKeyDown, onFocus, onBlur, className = "", placeholder, blurredPlaceholder, - autoFocus, initialValue, collapsed, enableRoomSearchFocus, ...props } = this.props; + autoFocus, initialValue, collapsed, ...props } = this.props; // check for collapsed here and // not at parent so we keep From eac29186a6d0179834676a0079a8c04a9a7b1194 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 5 Jan 2022 10:00:28 +0000 Subject: [PATCH 3/3] delint --- src/components/structures/SearchBox.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/structures/SearchBox.tsx b/src/components/structures/SearchBox.tsx index 359762cfc1c..86058a957af 100644 --- a/src/components/structures/SearchBox.tsx +++ b/src/components/structures/SearchBox.tsx @@ -20,10 +20,8 @@ import { throttle } from 'lodash'; import classNames from 'classnames'; import { Key } from '../../Keyboard'; -import dis from '../../dispatcher/dispatcher'; import AccessibleButton from '../../components/views/elements/AccessibleButton'; import { replaceableComponent } from "../../utils/replaceableComponent"; -import { Action } from '../../dispatcher/actions'; interface IProps extends HTMLProps { onSearch?: (query: string) => void;