mirror of
https://github.com/element-hq/element-web
synced 2024-11-23 09:46:09 +03:00
Fix new line created when enter is pressed (#10064)
This commit is contained in:
parent
b7cd28bd29
commit
469228f45e
2 changed files with 23 additions and 3 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 () => {
|
||||||
|
|
Loading…
Reference in a new issue