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

Commit

Permalink
Fix new line created when enter is pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Feb 2, 2023
1 parent c8ca47f commit 0e68c8c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,33 @@ 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",
}),
);

// 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 () => {
Expand Down

0 comments on commit 0e68c8c

Please sign in to comment.