Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit ea7ac45

Browse files
authored
Fix spotlight cmd-k wrongly expanding left panel (#7463)
1 parent 6eea416 commit ea7ac45

File tree

3 files changed

+11
-42
lines changed

3 files changed

+11
-42
lines changed

src/components/structures/MatrixChat.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
794794
});
795795
break;
796796
case 'focus_room_filter': // for CtrlOrCmd+K to work by expanding the left panel first
797+
if (SettingsStore.getValue("feature_spotlight")) break; // don't expand if spotlight enabled
798+
// fallthrough
797799
case 'show_left_panel':
798800
this.setState({
799801
collapseLhs: false,

src/components/structures/RoomSearch.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ export default class RoomSearch extends React.PureComponent<IProps, IState> {
9393
private onAction = (payload: ActionPayload) => {
9494
if (payload.action === Action.ViewRoom && payload.clear_search) {
9595
this.clearInput();
96-
} else if (payload.action === 'focus_room_filter' && this.inputRef.current) {
96+
} else if (payload.action === 'focus_room_filter') {
9797
if (SettingsStore.getValue("feature_spotlight")) {
9898
this.openSpotlight();
9999
} else {
100-
this.inputRef.current.focus();
100+
this.inputRef.current?.focus();
101101
}
102102
}
103103
};
@@ -109,8 +109,12 @@ export default class RoomSearch extends React.PureComponent<IProps, IState> {
109109
};
110110

111111
private openSearch = () => {
112-
defaultDispatcher.dispatch({ action: "show_left_panel" });
113-
defaultDispatcher.dispatch({ action: "focus_room_filter" });
112+
if (SettingsStore.getValue("feature_spotlight")) {
113+
this.openSpotlight();
114+
} else {
115+
defaultDispatcher.dispatch({ action: "show_left_panel" });
116+
defaultDispatcher.dispatch({ action: "focus_room_filter" });
117+
}
114118
};
115119

116120
private onChange = () => {

src/components/structures/SearchBox.tsx

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ import { throttle } from 'lodash';
2020
import classNames from 'classnames';
2121

2222
import { Key } from '../../Keyboard';
23-
import dis from '../../dispatcher/dispatcher';
2423
import AccessibleButton from '../../components/views/elements/AccessibleButton';
2524
import { replaceableComponent } from "../../utils/replaceableComponent";
26-
import { Action } from '../../dispatcher/actions';
2725

2826
interface IProps extends HTMLProps<HTMLInputElement> {
2927
onSearch?: (query: string) => void;
@@ -37,11 +35,6 @@ interface IProps extends HTMLProps<HTMLInputElement> {
3735
autoFocus?: boolean;
3836
initialValue?: string;
3937
collapsed?: boolean;
40-
41-
// If true, the search box will focus and clear itself
42-
// on room search focus action (it would be nicer to take
43-
// this functionality out, but not obvious how that would work)
44-
enableRoomSearchFocus?: boolean;
4538
}
4639

4740
interface IState {
@@ -51,13 +44,8 @@ interface IState {
5144

5245
@replaceableComponent("structures.SearchBox")
5346
export default class SearchBox extends React.Component<IProps, IState> {
54-
private dispatcherRef: string;
5547
private search = createRef<HTMLInputElement>();
5648

57-
static defaultProps: Partial<IProps> = {
58-
enableRoomSearchFocus: false,
59-
};
60-
6149
constructor(props: IProps) {
6250
super(props);
6351

@@ -67,31 +55,6 @@ export default class SearchBox extends React.Component<IProps, IState> {
6755
};
6856
}
6957

70-
public componentDidMount(): void {
71-
this.dispatcherRef = dis.register(this.onAction);
72-
}
73-
74-
public componentWillUnmount(): void {
75-
dis.unregister(this.dispatcherRef);
76-
}
77-
78-
private onAction = (payload): void => {
79-
if (!this.props.enableRoomSearchFocus) return;
80-
81-
switch (payload.action) {
82-
case Action.ViewRoom:
83-
if (this.search.current && payload.clear_search) {
84-
this.clearSearch();
85-
}
86-
break;
87-
case 'focus_room_filter':
88-
if (this.search.current) {
89-
this.search.current.focus();
90-
}
91-
break;
92-
}
93-
};
94-
9558
private onChange = (): void => {
9659
if (!this.search.current) return;
9760
this.setState({ searchTerm: this.search.current.value });
@@ -137,7 +100,7 @@ export default class SearchBox extends React.Component<IProps, IState> {
137100
public render(): JSX.Element {
138101
/* eslint @typescript-eslint/no-unused-vars: ["error", { "ignoreRestSiblings": true }] */
139102
const { onSearch, onCleared, onKeyDown, onFocus, onBlur, className = "", placeholder, blurredPlaceholder,
140-
autoFocus, initialValue, collapsed, enableRoomSearchFocus, ...props } = this.props;
103+
autoFocus, initialValue, collapsed, ...props } = this.props;
141104

142105
// check for collapsed here and
143106
// not at parent so we keep

0 commit comments

Comments
 (0)