From 6b90fe20abbdc63af99dcb5f0eb63fed61e6615a Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 3 Jul 2024 18:02:02 +0100 Subject: [PATCH] Extract `focus_search` dispatch action into enum (#12721) * Extract `focus_search` dispatch action into enum Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * copypasta Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/structures/LoggedInView.tsx | 4 +--- src/components/structures/RoomView.tsx | 2 +- src/dispatcher/actions.ts | 5 +++++ test/components/structures/LoggedInView-test.tsx | 14 ++++++++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/components/structures/LoggedInView.tsx b/src/components/structures/LoggedInView.tsx index 4481e4f603..7b6e3e3840 100644 --- a/src/components/structures/LoggedInView.tsx +++ b/src/components/structures/LoggedInView.tsx @@ -458,9 +458,7 @@ class LoggedInView extends React.Component { handled = true; break; case KeyBindingAction.SearchInRoom: - dis.dispatch({ - action: "focus_search", - }); + dis.fire(Action.FocusMessageSearch); handled = true; break; } diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index 3ed1c52e89..3f9370da80 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -1196,7 +1196,7 @@ export class RoomView extends React.Component { ); } break; - case "focus_search": + case Action.FocusMessageSearch: this.onSearchClick(); break; diff --git a/src/dispatcher/actions.ts b/src/dispatcher/actions.ts index e577daa884..7cff1cc859 100644 --- a/src/dispatcher/actions.ts +++ b/src/dispatcher/actions.ts @@ -388,4 +388,9 @@ export enum Action { * Opens right panel with 3pid invite information */ View3pidInvite = "view_3pid_invite", + + /** + * Opens right panel room summary and focuses the search input + */ + FocusMessageSearch = "focus_search", } diff --git a/test/components/structures/LoggedInView-test.tsx b/test/components/structures/LoggedInView-test.tsx index 04c8b43811..27ab93f2b8 100644 --- a/test/components/structures/LoggedInView-test.tsx +++ b/test/components/structures/LoggedInView-test.tsx @@ -19,6 +19,7 @@ import { render, RenderResult } from "@testing-library/react"; import { ConditionKind, EventType, IPushRule, MatrixEvent, ClientEvent, PushRuleKind } from "matrix-js-sdk/src/matrix"; import { MediaHandler } from "matrix-js-sdk/src/webrtc/mediaHandler"; import { logger } from "matrix-js-sdk/src/logger"; +import userEvent from "@testing-library/user-event"; import LoggedInView from "../../../src/components/structures/LoggedInView"; import { SDKContext } from "../../../src/contexts/SDKContext"; @@ -26,6 +27,10 @@ import { StandardActions } from "../../../src/notifications/StandardActions"; import ResizeNotifier from "../../../src/utils/ResizeNotifier"; import { flushPromises, getMockClientWithEventEmitter, mockClientMethodsUser } from "../../test-utils"; import { TestSdkContext } from "../../TestSdkContext"; +import defaultDispatcher from "../../../src/dispatcher/dispatcher"; +import SettingsStore from "../../../src/settings/SettingsStore"; +import { SettingLevel } from "../../../src/settings/SettingLevel"; +import { Action } from "../../../src/dispatcher/actions"; describe("", () => { const userId = "@alice:domain.org"; @@ -384,4 +389,13 @@ describe("", () => { }); }); }); + + it("should fire FocusMessageSearch on Ctrl+F when enabled", async () => { + jest.spyOn(defaultDispatcher, "fire"); + await SettingsStore.setValue("ctrlFForSearch", null, SettingLevel.DEVICE, true); + + getComponent(); + await userEvent.keyboard("{Control>}f{/Control}"); + expect(defaultDispatcher.fire).toHaveBeenCalledWith(Action.FocusMessageSearch); + }); });