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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View file

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

View file

@ -149,8 +149,10 @@ describe("WysiwygComposer", () => {
it("Should not call onSend when Enter is pressed", async () => {
// When
const textbox = screen.getByRole("textbox");
fireEvent(
screen.getByRole("textbox"),
textbox,
new InputEvent("input", {
inputType: "insertParagraph",
}),
@ -158,6 +160,22 @@ describe("WysiwygComposer", () => {
// Then it does not send a message
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 () => {