From 340e3018445d3031ca2c0127191c7a175f6c6f9b Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 1 Aug 2023 10:06:37 +0100 Subject: [PATCH] Make keyboard handling in and out of autocomplete completions consistent (#11344) * Make keyboard handling in and out of autocomplete completions consistent * Add test --- src/components/views/rooms/BasicMessageComposer.tsx | 2 -- .../views/rooms/BasicMessageComposer-test.tsx | 12 ++++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/views/rooms/BasicMessageComposer.tsx b/src/components/views/rooms/BasicMessageComposer.tsx index 89709c796c..8f0bd168ad 100644 --- a/src/components/views/rooms/BasicMessageComposer.tsx +++ b/src/components/views/rooms/BasicMessageComposer.tsx @@ -554,8 +554,6 @@ export default class BasicMessageEditor extends React.Component autoComplete.onEscape(event); handled = true; break; - default: - return; // don't preventDefault on anything else } } else if (autocompleteAction === KeyBindingAction.ForceCompleteAutocomplete && !this.state.showVisualBell) { // there is no current autocomplete window, try to open it diff --git a/test/components/views/rooms/BasicMessageComposer-test.tsx b/test/components/views/rooms/BasicMessageComposer-test.tsx index 0d5faa3550..4215ce6e64 100644 --- a/test/components/views/rooms/BasicMessageComposer-test.tsx +++ b/test/components/views/rooms/BasicMessageComposer-test.tsx @@ -82,6 +82,18 @@ describe("BasicMessageComposer", () => { expect(transformedText).toBe(after + " "); } }); + + it("should not mangle shift-enter when the autocomplete is open", async () => { + const model = new EditorModel([], pc, renderer); + render(); + + const input = screen.getByRole("textbox"); + + await userEvent.type(input, "/plain foobar"); + await userEvent.type(input, "{Shift>}{Enter}{/Shift}"); + const transformedText = model.parts.map((part) => part.text).join(""); + expect(transformedText).toBe("/plain foobar\n"); + }); }); function generateMockDataTransferForString(string: string): DataTransfer {