1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-08-09 08:42:50 +03:00

Fix new line created when enter is pressed (#10064)

This commit is contained in:
Florian Duros
2023-02-03 10:48:12 +01:00
committed by GitHub
parent b7cd28bd29
commit 469228f45e
2 changed files with 23 additions and 3 deletions

View File

@@ -168,14 +168,16 @@ function handleInputEvent(event: InputEvent, send: Send, isCtrlEnterToSend: bool
case "insertParagraph": case "insertParagraph":
if (!isCtrlEnterToSend) { if (!isCtrlEnterToSend) {
send(); send();
}
return null; return null;
}
break;
case "sendMessage": case "sendMessage":
if (isCtrlEnterToSend) { if (isCtrlEnterToSend) {
send(); send();
}
return null; return null;
} }
break;
}
return event; return event;
} }

View File

@@ -149,8 +149,10 @@ describe("WysiwygComposer", () => {
it("Should not call onSend when Enter is pressed", async () => { it("Should not call onSend when Enter is pressed", async () => {
// When // When
const textbox = screen.getByRole("textbox");
fireEvent( fireEvent(
screen.getByRole("textbox"), textbox,
new InputEvent("input", { new InputEvent("input", {
inputType: "insertParagraph", inputType: "insertParagraph",
}), }),
@@ -158,6 +160,22 @@ describe("WysiwygComposer", () => {
// Then it does not send a message // Then it does not send a message
await waitFor(() => expect(onSend).toBeCalledTimes(0)); await waitFor(() => expect(onSend).toBeCalledTimes(0));
fireEvent(
textbox,
new InputEvent("input", {
inputType: "insertText",
data: "other",
}),
);
// The focus is on the last text node
await waitFor(() => {
const selection = document.getSelection();
if (selection) {
expect(selection.focusNode?.textContent).toEqual("other");
}
});
}); });
it("Should send a message when Ctrl+Enter is pressed", async () => { it("Should send a message when Ctrl+Enter is pressed", async () => {